TOKEN=c2hhMjU2OjczMzo5NmFhZWRkYWYyNDEyZDA3MjAyMDk1YjA1NzJjOTZmYTc2NTJlMDY0ZjQ2NmJlZGNhNDhkNTA2MjQ5NjUwMzU2
curl -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain/api/index.php/v1/tags'
Json output
curl -v -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain/api/index.php/v1/tags'
* Trying 192.168.1.100:80...
* Connected to joomla4.localdomain (192.168.1.100) port 80 (#0)
> GET /api/index.php/v1/tags HTTP/1.1
> Host: joomla4.localdomain
> User-Agent: curl/7.80.0
> Accept: */*
> Authorization: Bearer c2hhMjU2OjczMzo5NmFhZWRkYWYyNDEyZDA3MjAyMDk1YjA1NzJjOTZmYTc2NTJlMDY0ZjQ2NmJlZGNhNDhkNTA2MjQ5NjUwMzU2
>
* Mark bundle as not supporting multiuse
**< HTTP/1.1 404 Not Found**
< Server: nginx/1.20.2
< Date: Tue, 18 Jan 2022 02:15:02 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/7.4.26
< Set-Cookie: 50f95936919a44dd4dca5540fa2cbec9=qtslkjbh8o77vtfura6lds43p5; path=/; HttpOnly
< x-frame-options: SAMEORIGIN
< referrer-policy: strict-origin-when-cross-origin
< cross-origin-opener-policy: same-origin
< Permissions-Policy: interest-cohort=()
< Expires: Wed, 17 Aug 2005 00:00:00 GMT
< Last-Modified: Tue, 18 Jan 2022 02:15:02 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
<
<!DOCTYPE html>
<html lang="en-gb" dir="ltr">
<head>
<meta charset="utf-8">
Proof the base URL is OK:
curl -v http://joomla4.localdomain
* Trying 192.168.1.100:80...
* Connected to joomla4.localdomain (192.168.1.100) port 80 (#0)
> GET / HTTP/1.1
> Host: joomla4.localdomain
> User-Agent: curl/7.80.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.20.2
< Date: Tue, 18 Jan 2022 02:02:53 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/7.4.26
< Set-Cookie: 50f95936919a44dd4dca5540fa2cbec9=2j00h512r8einus9p7mmlcd4h4; path=/; HttpOnly
< x-frame-options: SAMEORIGIN
< referrer-policy: strict-origin-when-cross-origin
< cross-origin-opener-policy: same-origin
< Permissions-Policy: interest-cohort=()
< Expires: Wed, 17 Aug 2005 00:00:00 GMT
< Last-Modified: Tue, 18 Jan 2022 02:02:53 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
<
<!DOCTYPE html>
$ uname -a
Linux tower 5.10.89-1-MANJARO #1 SMP PREEMPT Wed Dec 29 18:09:17 UTC 2021 x86_64 GNU/Linux
Labels |
Added:
No Code Attached Yet
|
you need to have only 1 api-authentication plugin enabled
@nobicycle Please disable the "API Authentication - Web Services Basic Auth" and report back if the error persists or not. Thanks in advance.
Thanks for replies.
Using a freshly installed 4.06 without "API Authentication - Web Services Basic Auth" disabled, obviously with new token, I get the same error.
$ TOKEN=c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
$ curl -v -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain/api/index.php/v1/tags'
* Trying 192.168.1.100:80...
* Connected to joomla4.localdomain (192.168.1.100) port 80 (#0)
> GET /api/index.php/v1/tags HTTP/1.1
> Host: joomla4.localdomain
> User-Agent: curl/7.80.0
> Accept: */*
> Authorization: Bearer c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Server: nginx/1.20.2
< Date: Wed, 19 Jan 2022 04:14:34 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/7.4.26
< Set-Cookie: d60f2bae230aacfd0c1398733fdc3cec=htb2re5ho603qb1463tefhknj0; path=/; HttpOnly
< x-frame-options: SAMEORIGIN
< referrer-policy: strict-origin-when-cross-origin
< cross-origin-opener-policy: same-origin
< Permissions-Policy: interest-cohort=()
< Expires: Wed, 17 Aug 2005 00:00:00 GMT
< Last-Modified: Wed, 19 Jan 2022 04:14:34 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
<
<!DOCTYPE html>
<html lang="en-gb" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="
Also with a different request (users) ... the same
$ curl -v -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain/api/index.php/v1/users'
* Trying 192.168.1.100:80...
* Connected to joomla4.localdomain (192.168.1.100) port 80 (#0)
> GET /api/index.php/v1/users HTTP/1.1
> Host: joomla4.localdomain
> User-Agent: curl/7.80.0
> Accept: */*
> Authorization: Bearer c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
Again, base url is OK
$ curl -v -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain/'
* Trying 192.168.1.100:80...
* Connected to joomla4.localdomain (192.168.1.100) port 80 (#0)
> GET / HTTP/1.1
> Host: joomla4.localdomain
> User-Agent: curl/7.80.0
> Accept: */*
> Authorization: Bearer c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
To me it looks like server error, wrong path or something.
Again, base url is OK
The base url may be ok, but what about whole path?
made i quick test with nginx and confirm what is reported all fine with apache
Nginx server definition:
server {
listen joomla4.localdomain:80;
server_name joomla4.localdomain ;
server_name_in_redirect off;
root /srv/http/joomla4;
client_max_body_size 20M;
index index.php index.phtml index.html;
error_log /var/log/joomla.log;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#correctly handle request like /test.php/foo/blah.php or /test.php/.
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass php74;
fastcgi_index index.php;
include /etc/nginx/fastcgi.conf; #Debian fastcgi_params
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Server running fine in browser
After runing the curle requests, there were no errors in the server log /var/log/joomla.log
Title |
|
Since apache was confirmed above OK, I tried it:
I have apache 2.4.52 running on port 8011
The Cassiopea website opens fine. API Authentication - Web Services Joomla Token plugin enabled
Same Token
It produces 401 Unauthorized
$ curl -v -H "Authorization: Bearer $TOKEN" 'http://joomla4.localdomain:8011/api/index.php/v1/users'
* Trying 192.168.1.100:8011...
* Connected to joomla4.localdomain (192.168.1.100) port 8011 (#0)
> GET /api/index.php/v1/users HTTP/1.1
> Host: joomla4.localdomain:8011
> User-Agent: curl/7.80.0
> Accept: */*
> Authorization: Bearer c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Date: Thu, 20 Jan 2022 12:54:00 GMT
< Server: Apache/2.4.52 (Unix)
< x-frame-options: SAMEORIGIN
< referrer-policy: strict-origin-when-cross-origin
< cross-origin-opener-policy: same-origin
< Permissions-Policy: interest-cohort=()
< X-Powered-By: JoomlaAPI/1.0
< Expires: Wed, 17 Aug 2005 00:00:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Last-Modified: Thu, 20 Jan 2022 12:54:00 GMT
< Transfer-Encoding: chunked
< Content-Type: application/vnd.api+json; charset=utf-8
<
* Connection #0 to host joomla4.localdomain left intact
*
Server config:
<VirtualHost joomla4.localdomain:8011>
ServerName joomla4.localdomain
ServerAdmin a@b.c
DocumentRoot /srv/http/joomla4/
<Directory /srv/http/joomla4>
Allowoverride all
</Directory>
DirectoryIndex index.php index.html
<FilesMatch .php$>
SetHandler "proxy:unix:/run/php74-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
</VirtualHost>
can you try the following
curl --location --request GET 'http://yoursite.loc/api/index.php/v1/content/articles' \
--header 'X-Joomla-Token: yourtoken' \
--data-raw ''
or via postman when your server is apache
can you try the following
curl --location --request GET 'http://yoursite.loc/api/index.php/v1/content/articles' \ --header 'X-Joomla-Token: yourtoken' \ --data-raw ''
or via postman when your server is apache
$ TOKEN=c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh
[user@tower ~]$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/content/articles' \
--header "X-Joomla-Token: $TOKEN" \
--data-raw ''
{"links":{"self":"http:\/\/joomla4.localdomain:8011\/api\/index.php\/v1\/content\/articles"},"data":[],"meta":{"total-pages":0}}
Same thing but root url:
$ curl --location --request GET 'http://joomla4.localdomain:8011/' --header "X-Joomla-Token: $TOKEN" --data-raw ''
Produces root page html OK.
so with apache it's working right ? @nobicycle
Requests below ... OK
USERS
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/users' --header "X-Joomla-Token: $TOKEN" --data-raw ''ata-raw ''
{"links":{"self":"http:\/\/joomla4.localdomain:8011\/api\/index.php\/v1\/users"},"data":[{"type":"users","id":"324","attributes":{"id":324,"name":"admin","username":"admin","email":"email@protonmail.ch","block":0,"sendEmail":1,"registerDate":"2022-01-19 04:07:36","lastvisitDate":"2022-01-21 09:18:00","lastResetTime":null,"resetCount":0,"group_count":1,"group_names":"Super Users"}}],"meta":{"total-pages":1}}
SITE MENUS
curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/menus/site' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"links":{"self":"http:\/\/joomla4.localdomain:8011\/api\/index.php\/v1\/menus\/site"},"data":[{"type":"menus","id":"1","attributes":{"id":1,"menutype":"mainmenu","title":"Main Menu","description":"The main menu for the site","client_id":0}}],"meta":{"total-pages":1}}
But articles ... after creating one, title 'test', article-text 'test' and saving ...
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/contents/articles' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"errors":[{"title":"Resource not found","code":404}]}```
Note, the doc https://docs.joomla.org/J4.x:Joomla_Core_APIs#Get_List_of_Articles says the call whould be with content, not contents
But if I do that:
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/content/articles' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"errors":{"code":500,"title":"Internal server error"}}
so with apache it's working right ? @nobicycle
Hi alikon, I replied o you above.
Any idea how to debug nginx?
Single Menu Fails
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/menus/site/101' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"errors":[{"title":"Resource not found","code":404}]}
All menus is OK```
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/menus/site' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"links":{"self":"http://joomla4.localdomain:8011/api/index.php/v1/menus/site"},"data":[{"type":"menus","id":"1","attributes":{"id":1,"menutype":"mainmenu","title":"Main Menu","description":"The main menu for the site","client_id":0}}],"meta":{"total-pages":1}}
you should use this for menu item {{base_path}}/api/index.php/v1/menus/site/items/101
curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/menus/site/101' --header "X-Joomla-Token: $TOKEN" --data-raw ''
Alikon, thank you. I misread the api doc.
How about Content . Do you confirm the error below in apache:
$ curl --location --request GET 'http://joomla4.localdomain:8011/api/index.php/v1/content/articles' --header "X-Joomla-Token: $TOKEN" --data-raw ''
{"errors":{"code":500,"title":"Internal server error"}}
Note: I tested all these routes with GET
banners
banners/categories
banners/clients
config/application
contacts
contacts/categories
content/articles
content/categories
extensions
fields/contacts/categories
fields/contacts/contact
fields/contacts/mail
fields/content/articles
fields/content/categories
fields/groups/contacts/categories
fields/groups/contacts/contact
fields/groups/contacts/mail
fields/groups/content/articles
fields/groups/content/categories
fields/groups/users
fields/users
languages
languages/content
menus/administrator
menus/administrator/items
menus/site
menus/site/items
messages
modules/administrator
modules/site
newsfeeds/categories
newsfeeds/feeds
plugins
privacy/consents
privacy/requests
redirects
tags
templates/styles/administrator
templates/styles/site
users
I cannot confirm your findings aboutcom_content
endpoints,
i need more details for that
what i can confirm is about {{base_path}}/api/index.php/v1/languages
i'm still struggle to understand what it's supposed to be
p.s
thank you for testing all the endopints
"i need more details for that"
I am using official Joomla Documentation
https://docs.joomla.org/J4.x:Joomla_Core_APIs#Create_Menu
Some errors during testing:
Install Language
curl -X POST -H "Content-Type: application/json" /api/index.php/v1/languages -d
{
"package": "pkg_fr-FR"
}
curl --header X-Joomla-Token: c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh -X POST -H Content-Type: application/json http://joomla4.localdomain:8011/api/index.php/v1/languages -d {"package": "pkg_nl-NL"}
{
"errors": [
{
"code": 500,
"title": "Internal server error"
}
]
}
)
Get Single Content Language
curl -X GET /api/index.php/v1/v1/languages/content/{language_id}
##Testing
**curl --header X-Joomla-Token: c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh -X GET -H Content-Type: application/json http://joomla4.localdomain:8011/api/index.php/v1/languages/content/213 -d ''
{
"errors": [
{
"title": "Resource not found",
"code": 404
}
]
}**
Update Content Language
##Documentation
Update Content Language
curl -X PATCH -H "Content-Type: application/json" /api/index.php/v1/languages/content/{language_id} -d
{
"description": "",
"lang_code": "en-GB",
"metadesc": "",
"metakey": "",
"sitename": "",
"title": "English (en-GB)",
"title_native": "English (United Kingdom)"
}
##Testing
curl --header 'X-Joomla-Token: c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh' \
-X PATCH -H 'Content-Type: application/json' \
'http://joomla4.localdomain:8011/api/index.php/v1/languages/content/213' \
-d '{ "description": "", "lang_code": "en-GB", "metadesc": "", "metakey": "", "sitename": "", "title": "English (en-GB)", "title_native": "English (United Kingdom)" }'
{"errors":[{"title":"Field required: URL Language Code"}]}
Get Single Article
##Documentation
curl -X GET /api/index.php/v1/content/articles/{article_id}
##Testing
curl --header 'X-Joomla-Token: c2hhMjU2OjMyNDplZmQ0NzViYjMwZDU3ODQ0YWNkY2QyZDU1NTFhNDI0Mzg4MTBlNGE3OWJiOGYxYWRiNjYyZGY2NjA5ODYxNjVh' \
-X PATCH -H 'Content-Type: application/json' \
'http://joomla4.localdomain:8011/api/index.php/v1/languages/content/213' \
-d '{ "description": "", "lang_code": "en-GB", "metadesc": "", "metakey": "", "sitename": "", "title": "English (en-GB)", "title_native": "English (United Kingdom)" }'
{"errors":[{"title":"Field required: URL Language Code"}]}
Title |
|
curl -X GET /api/index.php/v1/v1/languages/content/{language_id}
Be sure to use the ID value under System > Content Languages.
Labels |
Added:
Information Required
|
I was having a similar issue with Joomla 4.1.2 running Nginx 1.18.0 on Ubuntu 20.04. No Joomla API calls were working until I changed my Nginx location config as follows (first line with location directive was only change I made):
location ~ [^/]\.php(/|$) {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
which I got from here. Previously had the 1st line as:
location ~ .php$ {
Interested if this fixes your issue.
Sorry for the late reply, which is a 'no', , but I gave up on the API ever working. People have moved on to items such as cookie handling in Joomla 4.3 Never mind that the API core feature does not work on the most popular webserver.
Taking the standard example from the famous Joomla leader who specified the API: #27021
curl -H "Authorization: Bearer {token} " " http://{base_url}/api/index.php/v1/users
If I make your 'location' edit, this simple case produces :
{"errors":[{"title":"Forbidden"}]}
Whereas 'location ~ .php$ {' produces asolutely nothing.
Note: correct plugins are enabled.
Cecille filed a contact request on my site about this issue earlier today but did not leave a valid reply email address.
Even though I didn’t write the Joomla API, just its authentication plugin, I can help you as I do use the Joomla API extensively — it’s how I’ve been publishing software on my site, among other uses.
You have three problems which are simple to solve.
What you need to do is already documented in https://docs.joomla.org/Nginx
Please note that you have not done everything mentioned in there. Critically, you do not have the try
block for the api
folder. This is necessary for NginX to know what to do with URLs like /api/index.php/something
. If this is not present, NginX looks for a folder named index.php, it finds a file, therefore it falls back to the try
rule for the frontend SEF URLs. This is not a valid SEF URL which is why you are getting the 404 that was evident in your original post's cURL output.
Use the X-Joomla-Token
header instead:
-H "X-Joomla-Token: c2hhMjU2OjczMzo5NmFhZWRkYWYyNDEyZDA3MjAyMDk1YjA1NzJjOTZmYTc2NTJlMDY0ZjQ2NmJlZGNhNDhkNTA2MjQ5NjUwMzU2"
This is required. It's the only acceptable representation for JSON API responses.
-H "Accept: application/vnd.api+json"
After you fix your NginX config (and reload the configuration!) your request looks like this:
curl -X GET --location 'http://joomla4.localdomain/api/index.php/v1/tags' \
-H "X-Joomla-Token: c2hhMjU2OjczMzo5NmFhZWRkYWYyNDEyZDA3MjAyMDk1YjA1NzJjOTZmYTc2NTJlMDY0ZjQ2NmJlZGNhNDhkNTA2MjQ5NjUwMzU2" \
-H "Accept: application/vnd.api+json"
I hope this helps getting you back to the right direction :)
I hope this helps getting you back to the right direction :)
Thank you sir. Working now.
Also many thanks for your Joomla contributions and Akeeba.com products.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-12-13 01:19:32 |
Closed_By | ⇒ | nobicycle |
4.0.6 was released a few hours ago - please try that