InsideTheMachine
Coding for fun
  • Home
    • Jx! Standard Icons
    • plg_remote_markdown
    • Presentations
    • Joomla magazine
    • Joomla guide
  • The hard way
    • netGrep
    • Simple tasks
    • Kalender LG Steinlach-Zollern
  • Download
  • ImageWallCreator
  • Contact
  1. Aktuelle Seite:  
  2. Startseite
  3. Joomla Projects
  4. Joomla magazine

Magazine Articles Draft Section

!!! Magazine Articles Draft Section !!!

This section contains articles in preparation of articles in the Joomla Magazin

magazine-newsletter

Web Services API: Interface explained

Web Services API:

General introduction to the “external” interface of the Joomla Web Services API 

The external API interface of Joomla is actual the way programs or AI may interface the web site addressing web site components.  So you may want to know a bit more about it.

Another option for Access is an MCP server (Model Context Protocol) for AI, but that is a different story.  By the way, actually Joomla prepares its own included MCP server but there are already a lot of independend sulotions with different purposes out there.

This article intends to introduce you to the general interface, how the URL parts and the response data looks like. It does not contain a list of component endpoints (Which component has which endpoints). You will find links at the end of the article to lists though.

 

URL structure for Joomla API calls

Following is a general introduction to the URL path used when calling Joomla Webservice API functions

URL Uniform Resource Locator Structure (abbreviated):


www.example.com/documentation/index.html?p1=A&p2=B#ressource
\_____________/\_______________________/\________/\________/
       |                   |                 |         |
      host                path             query    fragment
 

Translated into Joomla API form:


example.com/api/index.php/v1/config/application?page[offset]=30&page[limit]=30
\__________/\____________/\___________________/\_____________________________/ 
     |            |                 |                        |     
    host       api path         endpoints                  query
 

The 'api path' leads direct into the root web site 'api' folder where the further parameter are collected. 

The endpoints are defined by web services plugins of joomla or components

The query parameters aligns to existing code in controller or model

Api path: /api/index.php/ -> webservice starting in web site '/api' folder
Endpoints: v1/config/application -> routes to address functionality
Query: pagination: ->page[offset]=30&page[limit]=30
  filter: ->filter[catid]=2&filter[state]=1
  sorting: ->list[ordering]=created&list[direction]=desc

    
Tip: Special characters like '[' and ']' must be converted to '%5B' and '%5D' like in other HTML queries

Endpoints:


v1   /secondhand /books /1/....
\___/ \________/\_____/\______/
  |       |        |      |   
version compon. section  sub sections
 
Version If the API route interface gets a B/C (breaking change) the version number will be increased
Component The component which handles the request
Section The controller/model/table part inside the component which handles the request
Sub section Variable (Id of a table item) or further route definition. Not to be confused with "?..." URL query part. The subsection definition may also be ASCII characters.

Examples:

  1. v1/secondhand/books
  2. v1/secondhand/ books/ 5
  3. v1/content/articles/1/contenthistory
Calling an Endpoint:

Besides using endpoints in php programms using the curl library a curl command may already exist on your command line (Win 11, macOs, Linux)

cURL (Client URL) is a free and open-source command-line tool used to transfer data to or from a server using a wide range of network protocols. 


curl -X GET \ 
-H "Accept: application/vnd.api+json" \
-H "X-Joomla-Token: YOUR_API_TOKEN" \
"https://example.com/api/index.php/v1/content/articles?
filter%5Bcategory%5D=12&filter%5Bsearch%5D=joomla
&page%5Blimit%5D=5"

The "https://example.com/api ..." part must be written in one line

Response example


{
    "links": {
        "self": "http://127.0.0.1/joommanual/api/index.php/v1/content/articles/2"
    },
    "data": {
        "type": "articles",
        "id": "2",
        "attributes": {
            "typeAlias": "com_content.article",
            "id": 2,
            "asset_id": 129,
            "title": "Working on Your Site",
            "alias": "working-on-your-site",

...

            "modified_by": {
                "data": {
                    "type": "users",
                    "id": "944"
                }
            }
        }
    }
}

 

Typical API endpoint definitions

Typical API route endpoint definitions

The commands supports the CRUD (Create, read, update, delete) operations.

The CRUD definitions for table items result in following API routes (example):

Command  Endpoint  Comment
GET  v1/content/articles  Lists all articles with content items 
GET  v1/content/articles/:id  Lists content items of article
POST  v1/content/articles  Creates new article with data
PATCH  v1/content/articles/:id  Writes parameters into selected article
DELETE  v1/content/articles/:id  Deletes selected article


':id' has to be replaced with the article number
Attention: There is no **PUT** command support in Joomla

Get: Fetch articles

Curl:


curl -X GET \ 
-H "Accept: application/vnd.api+json" \
-H "X-Joomla-Token: YOUR_API_TOKEN" \
"https://example.com/api/index.php/v1/content/articles

Response:


{
    "links": {
        "self": "http://127.0.0.1/joommanual/api/index.php/v1/content/articles"
    },
    "data": [
        {
            "type": "articles",
            "id": "11",
            "attributes": {
                "id": 11,
                "asset_id": 138,
                "title": "Typography",
                "alias": "typography",
                "state": 1,
                "access": 1,

... more articles

                "tags": {
                    "data": []
                }
            }
        }
    ],
    "meta": {
        "total-pages": 1
    }
}
Get: Fetch article by ID

Curl:


curl -X GET \ 
-H "Accept: application/vnd.api+json" \
-H "X-Joomla-Token: YOUR_API_TOKEN" \
"https://example.com/api/index.php/v1/content/articles/11

Response:


{
    "links": {
        "self": "http://127.0.0.1/joommanual/api/index.php/v1/content/articles"
    },
    "data": [
        {
            "type": "articles",
            "id": "11",
            "attributes": {
                "id": 11,
                "asset_id": 138,
                "title": "Typography",
                "alias": "typography",
                "state": 1,
                "access": 1,

... more

            },
            "tags": {
                "data": []
            },
            "modified_by": {
                "data": {
                    "type": "users",
                    "id": "944"
                }
            }
        }
    }
}
Post: Create article

Curl:


curl -X POST \
-H "Content-Type: application/json" \
-d '{"title":"My new article","catid":2,"articletext":"Hello world","language":"*"}' \ -H "Accept: application/vnd.api+json" \
-H "X-Joomla-Token: YOUR_API_TOKEN" \
 "https://example.com/api/index.php/v1/content/articles

Response:


{
    "links": {
        "self": "http://127.0.0.1/joommanual/api/index.php/v1/content/articles"
    },
    "data": [
        {
            "type": "articles",
            "id": "11",
            "attributes": {
                "id": 11,
                "asset_id": 138,
              "title": "My new article",
              "alias": "my-new-article",
                "state": 1,
                "access": 1,

... more

            },
            "tags": {
                "data": []
            },
            "modified_by": {
                "data": {
                    "type": "users",
                    "id": "944"
                }
            }
        }
    }
}
 
Patch: Update article by ID

Curl:


curl -X PATCH \ 
-H "Content-Type: application/json" \ -d '{"title":"Last article","catid":2}' \ -H "Accept: application/vnd.api+json" \
 -H "X-Joomla-Token: YOUR_API_TOKEN" \
"https://example.com/api/index.php/v1/content/articles/11

Response:


{
    "links": {
        "self": "http://127.0.0.1/joommanual/api/index.php/v1/content/articles"
    },
    "data": [
        {
            "type": "articles",
            "id": "11",
            "attributes": {
                "id": 11,
                "asset_id": 138,
              "title": "Last article",
              "alias": "my-new-article",
                "state": 1,
                "access": 1,

... more

            },
            "tags": {
                "data": []
            },
            "modified_by": {
                "data": {
                    "type": "users",
                    "id": "944"
                }
            }
        }
    }
}
Delete: Delete article by ID

Curl:


curl -X DELETE \ 
-H "Accept: application/vnd.api+json" \
-H "X-Joomla-Token: YOUR_API_TOKEN" \
 "http://127.0.0.1/joommanual/api/index.php/v1/content/articles/4"

Response:


% 

Before deleting the article needs to be in trash state. Patch article with publish=-2 

Not  CRUDE endpoints:

Most endpoint are accessing a db table. This makes the CRUDE endpoints easy to program.

Others 

  • media
  • custom fields
  •  

 

Custom Field endpoints


api/index.php/v1/fields/content/articles
 

Custom fields definitions have their own endpoints. These endpoints return the definitions of the fields (name, type, options), not the values stored in articles.

.../v1/fields/content/articles List all custom fields defined for articles
.../v1/fields/content/articles/7 Get one custom field by ID
.../v1/fields/groups/content/articles List custom field groups for articles
.../v1/fields/groups/content/articles/3 Get one field group by ID

 

POST, PATCH and DELETE commands are supported, so they can be created, changed or deleted

 

 

API URL query: pagination, filter, ordering

The query part starts with '?'. See above. 

The 'functions' used must be supported by the model of the addressed object. 

Pagination request

For pagination add


?page[offset]=90&page[limit]=30
 
Part Meaning
page[limit]=30 Number of results per page
page[offset]=90 Starting point, for pagination


which should be written like


?page%5Boffset%5D=90&page%5Blimit%5D=30
 

Each '[' and ']' has to be escaped. In curl '-g' (globoff) may be used to avoid this.

Filter request

Depending on your requested object Filter can adress several properties.  

For example: 'author', 'category', 'search', 'state', 'featured'

The following requests work on get article ...


?filter[category]=12&filter[state]=1&filter[search]=joomla%20webservices
?filter[category]=12&filter[state]=1&filter[search]=joomla+webservices
?filter[tag][]=3&filter[tag][]=22&filter[tag][]=18&filter[tag]
?filter[search]=content:Magritte

Spaces in search text may be encoded with '%20' or '+'. 

Ordering request

The direction is either 'ASC' or 'DESC'

The ordering does need to align to a module field name. Which may include the table abbreviation name


?list[ordering]=a.created&list[direction]=DESC
?list[ordering]=fp.ordering&list[direction]=asc

API route response 'json' data

API route responses

Responses from API routes follow a specific pattern. 

The results are contained in a  JSON style "string" with following sections 

  • links
  • data
  • meta

Links/meta excerpt from a response with four pages


{
    "links": {
        "self":"http://127.0.0.1/api_6x/api/index.php/v1/config/application
                ?page%5Boffset%5D=30&page%5Blimit%5D=30",
        "first": "http://127.0.0.1/api_6x/api/index.php/v1/config/application
                  ?page%5Boffset%5D=0&page%5Blimit%5D=30",
        "previous": "http://127.0.0.1/api_6x/api/index.php/v1/config/application
                     ?page%5Boffset%5D=0&page%5Blimit%5D=30",
        "next": "http://127.0.0.1/api_6x/api/index.php/v1/config/application
                 ?page%5Boffset%5D=60&page%5Blimit%5D=30",
        "last": "http://127.0.0.1/api_6x/api/index.php/v1/config/application
                 ?page%5Boffset%5D=90&page%5Blimit%5D=30"
    },
    "data": [ ... ],

    "meta": {
        "total-pages": 4
    }
}
 
Links / meta sections of API response
Pagination
  • links:
    • self: The link used in the API call
    • first: First set in pagination lists
    • previous: Previous set in pagination lists
    • next: Next set in pagination lists
    • last: Last set in pagination lists 
  • meta:
    • total-pages: Count of sets

The links and the "meta: total-pages" sections support easy pagination handling by direct use of the links. Each link contains the page offset in items and the number of items to return.

The data section contains the data of the response.

Using curl as tool to acces the Joomla webservices API

example that fetches articles from category ID 12 whose title or text matches “joomla”, sorted by newest first and limited to 5 results:

curl -g -X GET \
  -H "Accept: application/vnd.api+json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  "https://example.com/api/index.php/v1/content/articles?filter[category]=12&filter[search]=joomla&list[fullordering]=a.created DESC&page[limit]=5&page[offset]=0"

The URL broken down

Part Meaning
/api/index.php/v1/content/articles Articles endpoint of the Joomla 4/5 Web Services API
filter[category]=12 Only articles in category ID 12
filter[search]=joomla Free-text search on the article
list[fullordering]=a.created DESC Sort by creation date, newest first
page[limit]=5 Number of results per page
page[offset]=0 Starting point, for pagination

 

yyy

 

  • -g (globoff): curl otherwise interprets [ and ] as URL globbing patterns and throws an error. Alternatively, URL-encode them as %5B and %5D:
 

have to mask the square brackets for filter with backslashes. For example:

curl -H "Authorization: Bearer MY_AUTH_TOKEN" "https://example.org/api/index.php/v1/content/articles?filter\[featured\]=1"

-------

Spaces in search:

In curl '-g (globoff)' may be used to 

No. The brackets belong only to the parameter name (filter[search]), not to the value. The value just needs to be URL-encoded, and in curl the whole URL should be in quotes so the shell doesn’t misread it.

Option 1: encode the space yourself

 
curl -g -H "Accept: application/vnd.api+json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  "https://example.com/api/index.php/v1/content/articles?filter[search]=joomla%20web%20services"

+ instead of %20 also works in a query string: filter[search]=joomla+web+services.

Option 2: let curl do the encoding

 
curl -g -G -H "Accept: application/vnd.api+json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  --data-urlencode "filter[search]=joomla web services" \
  "https://example.com/api/index.php/v1/content/articles"

Here -G turns the --data-urlencode data into query-string parameters, so you can write the search text with normal spaces. This is the easiest form to read in an article.

Notes

  • A raw, unencoded space inside the URL string can cause a 400 error or be cut off, depending on the curl version and server, so don’t rely on it.
  • As far as I know, Joomla treats the whole value as one search string rather than splitting it into separate words, so joomla web services looks for that phrase. I haven’t confirmed this in the docs, so test it on your own installation before stating it in your article.

 

 

Webservice API definitions for articles

Webservice API definitions for articles 

here is not the place for the list of all possible endpoints so just a list for articles to get a genaral feling.

For more look to [ToDo Link to groups  or more ... @herman]()

Following is a Swagger UI formatted definition of the article endpoints. It was created with the  Web Services Documentation by Joomla!Labs. It is followed by a set of HTTP status codes returned. 

Content Operations related to content
Articles Articles for content
 GET/content/articlesGet list of articles
 POST/content/articlesCreate new item in articles
 GET/content/articles/{id}Get single item from articles
 PATCH/content/articles/{id}Update item in articles
 DELETE/content/articles/{id}Delete item from articles
Categories Categories for content
 GET/content/categoriesGet list of categories
 POST/content/categoriesCreate new item in categories
 GET/content/categories/{id}Get single item from categories
 PATCH/content/categories/{id}Update item in categories
 DELETE/content/categories/{id}Delete item from categories
Fields
Articles Articles fields for content
 GET/fields/content/articlesGet list of articles
 POST/fields/content/articlesCreate new item in articles
 GET/fields/content/articles/{id}Get single item from articles
 PATCH/fields/content/articles/{id}Update item in articles
 DELETE/fields/content/articles/{id}Delete item from articles
Categories Categories fields for content
 GET/fields/content/categoriesGet list of categories
 POST/fields/content/categoriesCreate new item in categories
 GET/fields/content/categories/{id}Get single item from categories
 PATCH/fields/content/categories/{id}Update item in categories
 DELETE/fields/content/categories/{id}Delete item from categories
Groups
Articles Articles field groups for content
 GET/fields/groups/content/articlesGet list of articles
 POST/fields/groups/content/articlesCreate new item in articles
 GET/fields/groups/content/articles/{id}Get single item from articles
 PATCH/fields/groups/content/articles/{id}Update item in articles
 DELETE/fields/groups/content/articles/{id}Delete item from articles
Categories Categories field groups for content
 GET/fields/groups/content/categoriesGet list of categories
 POST/fields/groups/content/categoriesCreate new item in categories
 GET/fields/groups/content/categories/{id}Get single item from categories
 PATCH/fields/groups/content/categories/{id}Update item in categories
 DELETE/fields/groups/content/categories/{id}Delete item from categories
Content History Content history for content
 GET/content/articles/{id}/contenthistoryDisplayList
 DELETE/content/articles/{id}/contenthistoryDelete
 PATCH/content/articles/{id}/contenthistory/keepKeep

After installing the package it lives on the help pages in section Web Services  ''API Explorer (Swagger)"  When clicking on the down arrow further data is revieled among other things which tell all the HTTP status codes of this command. Example Post article: 

 POST/content/articlesCreate new item in articles
Try it outParameters
No parameters
application/vnd.api+json  ▾Request body required
Example ValueSchema
{}
Responses
Code Description Links
201 Created successfully No links
400 Bad request No links
401 Unauthorized No links
422 Validation error No links
500 Server error No links

Links API endpoint

Links for "Web service API"

  • Marc Dechèvre: Playing with the Joomla Web Services (API)
    Description of the API based on the path from Excel data to articles
    Playing with the Joomla Web Services (API) - part 1
    Playing with the Joomla Web Services (API) - part 2
    Playing with the Joomla Web Services (API) - part 3
    Playing with the Joomla Web Services (API) - part 4
    https://slides.woluweb.be/api

  • Peter Martin: Using the Joomla Web Services API
    Very good overview:
    https://petermartin.nl/en/focus-on/joomla/web-services-api

  • Joomla Magazine: Using Joomla as a Headless CMS 
    Why use Joomla exclusively via the API—without content rendering 
    https://www.insidethemachine.de/index.php/joomla-projects/joomla-magazine

  • Joomla manual (developer) Web Services API
    Introduction and PHP webservices API programming 
    https://test.org/some/path/to/webservices

  • Joomla manual (developer) Web Services
    PHP webservices API programming 
    https://test.org/some/path/to/webservices

  • docs.joomla.org Communicate with the Joomla 4.x Web Services API
    External PHP scripts to access Web page per "Web service API"
    https://manual.joomla.org/docs/general-concepts/webservices

  • docs.joomla.org testJ4.x:Joomla Core APIs
    Outdated, but contains a readable list of endpoints (J!4)
    https://docs.joomla.org/J4.x:Joomla_Core_APIs

  • Joomla Magazine Using Bruno (the API Client) to play a.o. with Joomla Web Services
    Manual setup and calls of webservice APIs and see response data
    https://magazine.joomla.org/issues/2026/march-2026/using-bruno-the-api-client-to-play-a-o-with-joomla-web-services

  • test
    Test description
    https://test.org/some/path/to/webservices

  • Checkout postman and bruno

 

  • Impressum