Webservices relations

45 views
Skip to first unread message

Babak Hakimimehr

unread,
Jul 18, 2022, 2:35:41 PM7/18/22
to Joomla! General Development
hi
please help me

how i can get included key in my json response?

look at to this examples
first joomla single content result

{
"links": {
},
"data": {
"type": "articles",
"id": "13",
"attributes": {
"typeAlias": "com_content.article",
"id": 13,
"asset_id": 162,
"title": "Here's an article",
"alias": "my-article",
"state": 0,
"created": "2022-07-07 08:42:36",
"created_by": 54,
"created_by_alias": "",
"modified": "2022-07-07 08:42:36",
"modified_by": 54,
"publish_up": null,
"publish_down": null,
"images": [],
"urls": [],
"version": 1,
"metakey": "",
"metadesc": "",
"access": 1,
"hits": 0,
"metadata": [],
"featured": 0,
"language": "*",
"note": "",
"tags": [],
"featured_up": null,
"featured_down": null,
"text": "My text ",
"about-the-author": ""
},
"relationships": {
"category": {
"data": {
"type": "categories",
"id": "13"
}
},
"created_by": {
"data": {
"type": "users",
"id": "54"
}
},
"modified_by": {
"data": {
"type": "users",
"id": "54"
}
}
}
}
}


as you can see we have three relation
but my question is how can get more data about this relations
i search in google and i see this pages

https://jsonapi.org/
https://jsonapi.org/examples/
in this example page can see a json like this

{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!",
"body": "The shortest article. Ever."
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John"
}
}
]
}

In this example, there is a key named included, which contains the value of that relationship

please help me
thank you

MarkRS

unread,
Jul 18, 2022, 4:21:41 PM7/18/22
to Joomla! General Development
If you look at the tables in the Joomla database you'll see the keys which are the links. Just look for the fields that match,

babakhakimi Hakimimehr

unread,
Jul 19, 2022, 3:23:27 AM7/19/22
to Joomla! General Development
no i want included key in webservice response for every relationship
Please read my question again
This is not the answer I am looking for

MarkRS

unread,
Jul 19, 2022, 4:03:31 AM7/19/22
to Joomla! General Development
I have read your question carefully, and the answer I've already given is what you're looking for. It is telling you what "more data" you want.

If you look at the Joomla tables in question you'll see which fields are used to relate the tables together. For example you'll see the category table has an id field (mentioned in your list) and the content table has a catid field (not mentioned) it uses to link to the category.

The jsonapi website is useful in its explanation of json, not in any relation to the Joomla tables. The "included" data in the jsonapi example is not a key, it's an array of json objects containing data, probably linked to the articles data by a userid field in the article field to the id field in a people table but without seeing the data it's based on, that's just a guess. It's nothing to do with the Joomla data structure.

Babak Hakimimehr

unread,
Jul 19, 2022, 9:21:46 AM7/19/22
to Joomla! General Development
hi
So if I want to get the details of the category or created_by relationship, like the category name or creator (author) name, I have to make a new request to the api?

and can you send a sample of implementation of that?
i cant find anything
thank you

MarkRS

unread,
Jul 19, 2022, 11:11:41 AM7/19/22
to Joomla! General Development
The full api list is at https://docs.joomla.org/J4.x:Joomla_Core_APIs

Does that give you the information you need?
Reply all
Reply to author
Forward
0 new messages