Manipulating Clarity's Data with APIs
Liferay's headless APIs provide robust functionality to create, modify, and delete data across Liferay's components. Clarity's team wants to test manipulating data with APIs to better understand how to leverage them for their custom UIs and applications effectively. In these exercises, you'll use REST methods to create and modify Ticket object entries.
Exercise: Creating Clarity's Ticket Object Entries
Here, you'll leverage object APIs to create a new ticket and ensure it's successfully added to the system.
-
Sign in as the Clarity Admin user.
- Username:
admin@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
Click the REST Applications drop-down menu and select
c/tickets
. -
Under the Ticket section, expand the
postTicket
endpoint. -
Input the following code to the Request body:
-
Click Execute and verify the server response code is 200.
-
Expand the
getByExternalReferenceCode
endpoint. -
Enter
TCK0035
as theexternalReferenceCode
parameter and click Execute. -
Within the response body, verify that the returned information lists the previously created ticket:
Exercise: Updating Clarity's Tickets with PUT
Here, you'll modify the created ticket with a PUT request to add a description.
-
Within the Tickets object on API explorer, expand the
putByExternalReferenceCode
endpoint. -
Enter
TCK0035
for theexternalReferenceCode
parameter. -
Input the following code to the Request body:
Since this is a PUT request, the ticket's existing fields and values must still be included to retain the stored information.
-
Click Execute and verify the server response code is 200.
-
Expand the
getByExternalReferenceCode
endpoint. -
Enter
TCK0035
as theexternalReferenceCode
parameter and click Execute. -
Within the Response body, verify that the returned information lists the updated description:
Exercise: Updating Clarity's Tickets with PATCH
Here, you'll update the ticket by sending a PATCH request adjusting its priority.
-
Within the Tickets object on API explorer, expand the
patchByExternalReferenceCode
endpoint. -
Enter
TCK0035
for theexternalReferenceCode
parameter. -
Input the following code to the Request body:
-
Click Execute and verify the server response code is 200.
-
Expand the
getByExternalReferenceCode
endpoint. -
Enter
TCK0035
as theexternalReferenceCode
parameter and click Execute. -
Check that the server response code is 200 and that the description has been updated:
By leveraging the PATCH endpoint, existing field values were retained without being explicitly included in the PATCH call.
Exercise: Assigning Clarity's Tickets with Object Actions
Here, you'll configure the AssignToMe Object Action and leverage its API to assign yourself a ticket.
-
In your browser, go to the Clarity Public Enterprise Website.
-
Open the Global Menu (
), go to the Control Panel tab, and click Users and Organizations. -
Click on the Clarity Admin user and copy the User ID for use in a later step.
-
Open the Global Menu (
), go to the Control Panel tab, and click Objects. -
Go to the Ticketing folder and being editing Ticket.
-
Select the Actions tab and click Assign Ticket to Me.
-
Go to the Action Builder tab.
-
Under the Values section click Add (ICON).
-
Select the User to Tickets field and click Save.
-
Check the Input as a value checkbox.
-
In the New Value column add Clarity's User ID.
-
Click Save.
-
Navigate back to the API Explorer at http://localhost:8080/o/api.
-
Click on the REST Applications drop-down menu and select
c/tickets
. -
Expand the
putTicketAssignTicketToMe
endpoint for ERCs. -
Enter
TCK0035
for theexternalReferenceCode
parameter and click Execute. -
Verify that the server response code is 204.
NOTE
A 204 “No Content” response code means a request is successful but doen't include a response payload. -
Expand the
getByExternalReferenceCode
endpoint. -
Enter these parameters and click Execute.
Parameter Value externalReferenceCode TCK0035 nestedFields userToTicket
-
Verify in the Response body that the ticket has been assigned to Clarity Admin:
Exercise: Removing Clarity's Tickets with DELETE
Here, you'll delete the ticket by sending a DELETE request, permanently removing it from the system.
-
Within the Tickets object on API explorer, expand the
deleteByExternalReferenceCode
endpoint. -
Enter
TCK0035
for theexternalReferenceCode
parameter and click Execute. -
Verify the server responds with a 204:
-
Expand the
getByExternalReferenceCode
endpoint. -
Enter
TCK0035
as theexternalReferenceCode
parameter and click Execute. -
Verify a server response of
404
and Response body ofNot Found
, confirming the ticket's deletion:
Conclusion
Great! You've successfully used headless APIs to create, update, and remove data from Clarity's system. Clarity's developers can leverage these APIs within their planned dashboards to perform intricate data manipulation actions.
Next, you'll learn how to handle attachments with Liferay's headless APIs.
Capabilities
Product
Education
Contact Us