Uploading Clarity's Attachments with APIs
Attachments like documents, images, and other files enrich assets with valuable context and detail. Clarity’s developers would like to test attaching files with headless APIs to improve their team’s ability to programmatically augment products with media (e.g., graphics, flyers).
In this article, you’ll leverage APIs to upload an attachment to an existing commerce product.
Exercise: Adding Clarity’s PDF Attachments
Here you’ll use the Commerce Admin APIs to attach a flyer to the Classic Aviator Sunglasses product.
-
Sign in as the Clarity Admin user.
-
Username:
admin@clarityvisionsolutions.com
-
Password:
learn
-
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
In the upper right, click the REST Applications drop-down menu and select
headless-commerce-admin-catalog/v1.0
. -
Under the Attachment section, expand the
postProductByExternalReferenceCodeAttachmentByBase64
endpoint. -
Add
3d607d51-b58d-d188-5a27-03041440d340
to theexternalReferenceCode
parameter. -
Input the following code to the Request body:
-
In your course workspace, navigate to the
exercises/module-3/flyer-base64.txt
file and copy its contents -
Replace the
%BASE64-PLACEHOLDER%
in the API Explorer Request body with the copied contents, retaining the surrounding quotes. -
Click Execute.
The response body should be similar to the following: -
Copy the
src
field’s URL value, paste it into your browser's address bar, and change the security protocol fromhttps
tohttp
to download the PDF. -
Once downloaded, open the file.
-
Navigate back to Clarity’s home page.
-
Open the Global Menu (
), go to the Commerce tab, and click Products. -
Click Classic Aviator Sunglasses.
-
Go to the Media tab and confirm that the flyer was added to the product.
Conclusion
Great! You can now leverage headless APIs to attach files to assets within Liferay. Next, you’ll learn how to leverage batch engine APIs to perform bulk exports and imports of data.
Capabilities
Product
Education
Contact Us