How to query related items in the rest api?

Hello,
i would like to query, from javascript, all the items that are linked to one, but i don’t know what is the correct syntax.
In the php api we can use: subjectValues , subjectValueTotalCount , and subjectProperties.
but how should an url be structured?
e.g. /api/items/ID?related

Thanks as always!

I’m not aware of a way to do this in the current release of Omeka, but, in the next release, the API response for a resource will include a @reverse key that contains all resources that are linked to the requested resource. See this pull request.

3 Likes

You can find all items related/linked to a specified item by using the item search/browse endpoint and using the “property” search:

/api/items?property[0][property]=0&property[0][type]=res&property[0][text]=<ID of item>

Passing 0 for the property subkey means to search across all properties, and the res search type means to search for items which link to the resource ID given in the text subkey.

1 Like

Thanks for both answers!
I was also wondering, if from a given item i want to query all the items it relates to (and not the inverted properties) i could select all the properties which contain "type": "resource" and get their ids.

Consequentially is there a way to make a single api call for all ids? e.g.

/api/items/ID&ID&ID

so i could get a response object like this?

[
    {
        "@context": "...",
        "@id": "..."
        ....
    },
    {
        "@context": "...",
        "@id": "..."
        ....
    },
    {
        "@context": "...",
        "@id": "..."
        ....
    }

I am asking this to avoid making plenty of api calls per item.

You can do a “search” query by multiple IDs at once, yes:

api/items?id[]=1&id[]=2&id[]=3

and so on.

1 Like

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.