OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums 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 7 years, 9 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #34215

    adamlundrigan
    Participant

    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
    Replies
  • #34216

    adamlundrigan
    Participant

    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:

    #34217

    adamlundrigan
    Participant

    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)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top