Testdriving RESTful APIs - help needed Topic is solved

General questions relating to Joomla! 4.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Testdriving RESTful APIs - help needed

Post by aftertaf » Wed Dec 01, 2021 11:40 pm

Hi,
I'm trying to test out the RESTful APIs in J!4.0.4, following the instructions here : https://magazine.joomla.org/all-issues/ ... taste-test

UsingPostman, i cannot get past this stage :
"Finally, use one of the GET endpoints to test that your endpoints are connecting to your site."

I get systematically a 404 :
{
"title": "Resource not found",
"code": 404
}

I've tried with 2 valid superusers' API keys, no joy.
When I remove all the text after base_path, i get a HTTP 200 and can reach the website OK.
{{base_path}}/api/index.php/v1/content/articles/ : NOK
{{base_path}} : OK

ACCESS logs:
54.86.50.139 - - [02/Dec/2021:00:34:37 +0100] "GET / HTTP/1.1" 200 13511 "-" "PostmanRuntime/7.28.4"
54.86.50.139 - - [02/Dec/2021:00:34:26 +0100] "GET /api/v1/content HTTP/1.1" 404 65 "-" "PostmanRuntime/7.28.4"
54.86.50.139 - - [02/Dec/2021:00:34:12 +0100] "GET /api/v1/content/articles/ HTTP/1.1" 404 65 "-" "PostmanRuntime/7.28.4"
54.86.50.139 - - [02/Dec/2021:00:33:58 +0100] "GET /api/index.php/v1/content/articles/ HTTP/1.1" 404 65 "-" "PostmanRuntime/7.28.4"
54.86.50.139 - - [01/Dec/2021:23:56:08 +0100] "POST /api/index.php/v1/content/article HTTP/1.1" 404 65 "-" "PostmanRuntime/7.28.4"
x.x.x.x - - [01/Dec/2021:23:55:40 +0100] "POST /api/index.php/v1/content/article HTTP/1.1" 406 40 "-" "Mozilla/5.0 (Windows NT; Windows NT 10.0; fr-FR) WindowsPowerShell/5.1.19041.1320"

I've checked all the system plugins are enables, CORS is enabled, but cannot find any other documentation online to troubleshoot more.
Any pointers highly appreciated.
(if any more info / details needed please don't hesitate !!)
Thanks

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17354
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Testdriving RESTful APIs - help needed

Post by toivo » Thu Dec 02, 2021 2:27 am

Postman seems to work all right, based on the instructions in the article how to get an API key and link it to the downloaded collection. Did you set up the Auth information and also the variable {{base_path}} as the URL of the website for the collection so that individual requests inherit it?
Toivo Talikka, Global Moderator

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Thu Dec 02, 2021 8:00 am

Hi, Yes i have done both.
Base URL is my https:// url without a trailing /, and the API key is set as per the video.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17354
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Testdriving RESTful APIs - help needed

Post by toivo » Thu Dec 02, 2021 9:21 am

Are you connecting to a localhost site or to a remote site? Some host configure run mod_security in their server, which may block the API, unless specific rules allow those connections.
Toivo Talikka, Global Moderator

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Thu Dec 02, 2021 10:31 am

toivo wrote:
Thu Dec 02, 2021 9:21 am
Are you connecting to a localhost site or to a remote site? Some host configure run mod_security in their server, which may block the API, unless specific rules allow those connections.
Hi, this is a hosted site, remote (lws cPanel)... I've turned off mod_security to see if it helps, and it hasn't so far.

About to grab an akeeba backup to restore on a local XAMPP and test that way. I was also thinking that this is linked to the hosting somehow, otherwise the forum/bugtracker would have had way more posts on this 'not working' :). ill add more info here as i get this tested. thanks!!

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Thu Dec 02, 2021 12:37 pm

localhost/XAMPP - postman can reach & read via GET API calls.
So its my hosting that is gnarly - when i get useful info back i'll post it here in case it can help others :) thanks all.

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Tue Dec 07, 2021 2:43 pm

My hosting provider says they've found the root cause and are in the process of correcting it. So nothing to do with J4 at all. Haven't got the explanation or the confirmation that it is fixed yet. Will post if it is helpful for others that may face this in the future . .

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Sun Jun 05, 2022 12:35 pm

Hi (again).
So this is now working, and I've updated to J4.1.4 and have the most recent Postman API collection imported for Joomla.
I have tested and can perform some GETs & PATCHs.
I do have an issue when trying to PATCH a user though :
This is the API call : {{base_url}}/{{base_path}}/users/{{user_id}}

When i try to update any user field/property, I get the error :
"errors": [
{
"title": "The passwords you entered do not match. Please enter your desired password in the password field and confirm your entry by entering it in the confirm password field."
}
]

Status 400 Bad Request

I checked with different fields, and by 'wrapping' in "data" and "attributes" elements, as raw JSON but same error . .
Anyone had any luck at this ?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17354
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Testdriving RESTful APIs - help needed

Post by toivo » Mon Jun 06, 2022 1:24 am

Just confirmed that patching a user produces the error prompting for password and password confirmation and then saw your bug report [#37991] - [4.1.4] (and [4.2.0dev3]) - Webservices PATCH to update a user fails with status 400. We'll see what happens.
Toivo Talikka, Global Moderator

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

Re: Testdriving RESTful APIs - help needed

Post by aftertaf » Mon Jun 06, 2022 7:52 am

Thanks!

User avatar
aftertaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sat Jan 23, 2010 1:27 pm
Contact:

[RESOLVED] - Joomla User APIs

Post by aftertaf » Mon Jun 06, 2022 11:13 am

There's a merge request (https://github.com/joomla/joomla-cms/pull/37994) that fixes this issue. Tested on my end and works fine with the fix applied.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17354
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Testdriving RESTful APIs - help needed

Post by toivo » Mon Jun 06, 2022 1:28 pm

Confirmed, the fix works all right.
Toivo Talikka, Global Moderator


Locked

Return to “General Questions/New to Joomla! 4.x”