Advertisement

Joomla API to post content Topic is solved

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
ninjus
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Jan 06, 2025 9:16 pm

Joomla API to post content

Post by ninjus » Mon Jan 06, 2025 9:26 pm

Hi

First post.

I'm in no way a developer so no business posting in the coding section but I wanted to find a way to add and update my Joomla posts including custom fields using the API. I found it hard to get any clarity on getting custom fields to work but after some back and forth with chatgpt (I know right.. that normally never works haha) I got something working. By adding an article with custom fields first and then using GET I could work backwards from that.

I'm sharing a summary as its what I needed and couldn't find it here.
I know its not rocket science haha... Just hope it helps someone else.

The custom fields in the examples are town, county and top-image. Enjoy.

Here’s a full summary of the POST, PATCH, and GET examples based on what we’ve learned, incorporating text fields and media fields. These examples should cover most scenarios for interacting with Joomla’s API.

---

POST Request
This creates a new article with custom fields.

cURL Command:
curl -X POST "http://domain.com/api/index.php/v1/content/articles" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "New Article with Custom Fields",
"catid": "2",
"introtext": "This is an article created via the API with custom fields.",
"fulltext": "This is the full content of the article.",
"state": "1",
"language": "*",
"town": "Dublin",
"county": "Dublin County",
"top-image": {
"imagefile": "images/joomla_black.png#joomlaImage://local-images/joomla_black.png?width=225&height=50",
"alt_text": "Joomla Logo"
}
}'


---

PATCH Request
This updates an existing article (e.g., article with ID 6) and modifies its fields.

cURL Command:
curl -X PATCH "http://domain.com/api/index.php/v1/content/articles/6" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Article with Media Field",
"catid": "2",
"introtext": "Updated introtext with media field.",
"fulltext": "Updated full content including media field.",
"state": "1",
"language": "*",
"town": "Dublin",
"county": "Dublin County",
"top-image": {
"imagefile": "images/joomla_black.png#joomlaImage://local-images/joomla_black.png?width=225&height=50",
"alt_text": "Joomla Logo"
}
}'


---

GET Request
This retrieves an existing article and its custom fields (e.g., article with ID 6).

cURL Command:
curl -X GET "http://domain.com/api/index.php/v1/content/articles/6" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"


Example Response:
{
"links": {
"self": "http://domain.com/api/index.php/v1/content/articles/6"
},
"data": {
"type": "articles",
"id": "6",
"attributes": {
"typeAlias": "com_content.article",
"id": 6,
"title": "Updated Article with Media Field",
"catid": 2,
"introtext": "Updated introtext with media field.",
"fulltext": "Updated full content including media field.",
"state": 1,
"language": "*",
"town": "Dublin",
"county": "Dublin County",
"top-image": {
"imagefile": "images/joomla_black.png#joomlaImage://local-images/joomla_black.png?width=225&height=50",
"alt_text": "Joomla Logo"
}
}
}
}


---

Notes for Each Request Type
#### POST:
Used to create a new article.
Requires title, catid, and optionally introtext, fulltext, state, and language.
Custom fields can be included as direct keys or nested JSON objects (for media).

#### PATCH:
Used to update an existing article.
Only include the fields you want to modify.
Custom fields behave the same as in a POST request.

#### GET:
Retrieves an article by ID.
Displays the full article data, including custom fields.

Advertisement
User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25355
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Joomla API to post content

Post by pe7er » Tue Jan 07, 2025 9:38 am

Welcome to Joomla forum!
Thank you for sharing your experiences with Joomla's Webservices API and Custom Fields!

The current Webservices API manual does not currently provide specific information on Custom Fields: https://manual.joomla.org/docs/next/gen ... bservices/

Could you improve the Webservices API manual regarding Custom Fields?
Thanks in advance!
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”