Forums OroPlatform OroPlatform – Programming Questions Returning relationship entities in JSON.API response

This topic contains 2 replies, has 1 voice, and was last updated by  adamlundrigan 1 year, 6 months ago.

  • Creator
  • #28734


    I’m using the JSON-API to retrieve custom entities:

    And I receive this response back from my application, as expected:

    Is there a way I can ask the API to return the whole serialized related entity instead of just the relationship link (type+id)? There are certain circumstances where I’d like to batch together all the related data so I can get it in one request.

    In the above example, for instance, I would presently need to do three API calls to render the schedule for this Course Offering (one to fetch the offering itself, two more to fetch each schedule entry of type “courseofferingtimes”)

    (Technically I could do it in two calls by doing /api/courseofferingtimes?filter[id]=10,11 instead of separate calls to /api/courseofferingtimes/10 and /api/courseofferingtimes/11 — but that’s still two total calls where I’d like to do one)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #28735


    Not sure if it’s the best or most efficient way but it can be accomplished by enumerating the fields for each associated entity inline, like so:

    (Note: these examples don’t use the same custom entity as I used in my original question)

    The JSON.API response will now have an “included” key with serialized copies of each related entity. Example:



    Thanks to @vsoroka on GitHub for pointing out a better way to do this (link). I didn’t think to look at the JSON.API docs, which in hindsight seems a pretty obvious course of action :/

    JSON.API has an “include” query string parameter which specifies the related entities that should be included in the response.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.