Mastering Consuming Liferay Headless APIs

Retrieving Clarity's Related Object Entries

Consuming related data enables complex querying to interact with associated assets and entries. To test querying related object entries, Clarity created two relationships for their Ticket object, including a one-to-many relationship with the Ticket object itself (allowing a ticket to have multiple related tickets).

In this exercise, you’ll query related object data using relationship endpoints and the nestedField parameter.

Here, you’ll retrieve related tickets within the API Explorer.

  1. Sign in as the Clarity Admin user.

    • Username: admin@clarityvisionsolutions.com

    • Password: learn

  2. Open the Global Menu (Global Menu icon), go to the Applications tab, and click Tickets.

  3. Find the first ticket with a User to Tickets value of “Renee,” and click on that ticket’s ID.
    Find the first ticket with a User to Tickets value of “Renee,” and click on that ticket’s ID.

  4. Set the Ticket to Tickets field to the “Test Client Extension Ticket” created in a previous exercise and click Save.

  5. Repeat steps 3 and 4 for the second ticket with a User to Tickets of “Renee.”
    You should now see two tickets related to the Test Client Extension Ticket:
    Repeat steps 3 and 4 for the second ticket with a User to Tickets of “Renee.”

  6. Navigate to the API Explorer at http://localhost:8080/o/api.

  7. Click on the REST Applications drop-down and select c/tickets.

  8. Under the Ticket section, expand the getTicketsPage endpoint.
    Under the Ticket section, expand the getTicketsPage endpoint.

  9. Set the following parameters and click Execute.

    Parameter Value
    nestedFields ticketToTickets
    pageSize 40
  10. Within the response body, find the ticketToTickets structure within each of the two tickets related to “Test Client Extension Ticket”.

    ...
    "taxonomyCategoryBriefs": [],
    "r_ticketToTickets_c_ticketId": 65848,
    "r_accountToTickets_accountEntryERC": "ACCT_IRIS",
    "userToTicketsERC": "USER_RENEE",
    "subject": "How to adjust or tighten my frames?",
    ...
    "taxonomyCategoryBriefs": [],
    "r_ticketToTickets_c_ticketId": 65848,
    "r_accountToTickets_accountEntryERC": "ACCT_IRIS",
    "userToTicketsERC": "USER_RENEE",
    "subject": "Main cleaning products",
    ...
    
    Both tickets should include a r_ticketToTickets_c_ticketId relationship pointing to the same ID. With the above values, the related ticket ID is 65848.
  11. Copy the related ticket’s ID.

  12. Under the Ticket section, expand the getTicketTicketToTicketsTicketPage endpoint.

  13. Paste the ID into the ticketId parameter and click Execute.
    Paste the ID into the ticketId parameter and click Execute.

  14. Examine the returned list to verify that only the two tickets related to “Test Client Extension Ticket” are returned.

    "lastPage": 1,
    "page": 1,
    "pageSize": 20,
    "totalCount": 2
    

Clarity can use similar relationships to retrieve lists of child tickets connected to single parent tickets within their dashboards.

Conclusion

Great! You’ve learned to leverage both the nestedFields parameter and relationship API endpoints to return related data. This provides an essential baseline to perform complex queries and manage relationships between object entries.

Next, you’ll learn about leveraging search and search suggestions APIs to quickly provide users with relevant results.

  • Exercise: Querying Clarity’s Related Ticket Data

  • Conclusion

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy