Using APIs to Import Clarity’s Content
Clarity wants to use leverage Liferay’s headless APIs to import content from their legacy systems. They also want to leverage headless APIs to import Clarity products from their Product Information Management system (PIM).
Exercise: Connecting to Headless APIs Using the API Explorer
Let’s see how headless APIs can be used by interacting with it through Liferay’s API Explorer. Here you’ll add a new blog post as Walter Douglas.
To do this,
-
Open the Site Menu (), expand Configuration, and select Site Settings.
-
Select Site Configuration under Platform.
-
Copy down the Site ID and save it for a future step.
-
Open the Site Menu (), expand Categorization, and select Categories.
-
Click Blog Posts under the Clarity vocabularies.
-
Select one of the categories in the list.
-
In your browser’s navigation bar, copy down the category’s ID that appears in the page URL. For example,
(...)categories_admin/vocabulary/37819/category/[category-id]
. You’ll use this ID in a later step. -
Open a new browser window and access Liferay’s API Explorer at
http://localhost:8080/o/api
. -
Scroll down to the Document section and expand the postSiteDocument endpoint.
Tip: To quickly find the endpoint, search the browser page for
postSiteDocument
. -
For the siteId field, enter the site ID for Clarity Public Enterprise Website.
-
For the document field, delete the default JSON content and uncheck Send empty value.
-
For file field, click Choose File and select
glasses-book.png
from the[repository-folder]/exercises/lesson-15/
folder. -
Click Execute.
This uploads a new image file to Clarity’s Documents and Media.
-
In the response body, look for the image’s ID. For example:
(...) "fileExtension" : "png", "fileName" : "glasses-book.png", "id" : [image-id], "keywords" : [ ], (...)
Copy down the image ID to use in the next step.
-
Scroll up to the BlogPosting section and expand the postSiteBlogPosting endpoint.
-
For siteId, enter the site ID for Clarity Public Enterprise Website.
-
For Request Body, delete the default JSON content.
-
From the training workspace, open the
blog-entry.json
file in the[repository-folder]/exercises/lesson-15/
folder.This file contains a blog post entry with a custom headline and body content.
-
Copy the contents of
blog-entry.json
into the Request Body field. -
Replace
{image-id}
and{category-id}
with your image ID and the blog category ID, respectively. -
Click Execute. Make sure the response code is
200
. -
Return to the Clarity Public Enterprise Website window, open the Site Menu (), expand Content & Data, and click Blogs.
-
Confirm the
Things I Find Interesting in Eyewear
blog post appears.
Exercise: Using Headless APIs to Batch Import Web Content
Clarity wants to import three legacy web articles from their old portal into their new enterprise website. Here you’ll add them using Liferay’s Headless APIs as Walter Douglas.
To do this,
-
Return to the browser window for Liferay’s API Explorer (
http://localhost:8080/o/api
). -
Scroll down to the StructuredContent section and expand the postSiteStructuredContentBatch endpoint.
-
For siteId, enter the site ID for Clarity Public Enterprise Website.
-
For Request Body, delete the default JSON content.
-
From the training workspace, open the
import-web-content-articles-batch.json
file in the[repository-folder]/exercises/lesson-15/
folder. -
Copy the contents of
import-web-content-articles-batch.json
into the Request Body field. -
Click Execute.
-
Return to the Clarity Public Enterprise Website window, open the Site Menu (), expand Content & Data, and click Web Content.
-
Open the Articles folder and confirm all three articles appear.
Exercise: Using Headless APIs to Batch Import Products
You can use REST APIs to import Clarity’s products from external systems to Liferay DXP, streamlining product management. Here you’ll use APIs to create products as Ian Miller.
To do this,
-
Sign in as Ian Miller.
- Username:
ian.miller@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Open the Global Menu (), go to the Commerce tab, and click Products.
Take note of the number of existing products (i.e. 3).
-
Open the Global Menu (), go to the Commerce tab, and click Catalogs.
-
Click Clarity Eyewear.
Copy down the catalog’s ID. You’ll use it in a later step.
-
Open a new browser window and access Liferay’s API Explorer at
http://localhost:8080/o/api
. -
Click the REST Applications drop-down menu and select headless-commerce-admin-catalog/v1.0.
-
Scroll down to the Product section and expand the postProductBatch endpoint.
-
For Request Body, delete the default JSON content.
-
From the training workspace, open the
import-products-batch.json
file in the[repository-folder]/exercises/lesson-15/
folder. -
Copy the contents of
import-products-batch.json
into the Request Body field and replace{catalog-id}
for all products with the Clarity Eyewear catalog ID. -
Click Execute.
-
Return to the Clarity Public Enterprise Website window, open the Global Menu (), go to the Commerce tab, and click Products.
-
Confirm eight new products appear.
Exercise: Using Headless to Import Taxonomy Categories
As a multinational company, Clarity has many business locations around the globe. To better support recruitment efforts, Clarity needs to define categories that they can apply to job openings for each office location. Some categories already exist, but others are still missing.
Here you’ll add the missing location categories as Clarity Admin.
To do this,
-
Sign in as the Clarity Admin user.
- Username:
admin@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Open the Global Menu (), go to the Applications tab, and click Asset Libraries.
-
Select the HR library and click Categories.
-
Go to the Location vocabulary in the left side menu.
Take note of the number of existing location categories (i.e. 14).
-
In your browser’s navigation bar, copy down the vocabulary’s ID that appears in the page URL. For example,
(...)categories_admin/vocabulary/[vocabulary-id]
. You’ll use this ID in a later step. -
Open a new browser window and access Liferay’s API Explorer at
http://localhost:8080/o/api
. -
Click the REST Applications drop-down menu and select headless-admin-taxonomy/v1.0.
-
Scroll down to the TaxonomyCategory section and expand the postTaxonomyVocabularyTaxonomyCategoryBatch endpoint.
-
For taxonomyVocabularyId, enter the vocabulary ID for Location.
-
For Request Body, delete the default JSON content.
-
From the training workspace, open the
import-taxonomy-categories-batch.json
file in the[repository-folder]/exercises/lesson-15/
folder. -
Copy the contents of
import-taxonomy-categories-batch.json
into the Request Body field. -
Click Execute.
-
Return to the HR Asset Library window and refresh the page.
The new locations should appear.
-
Click HR in the breadcrumb menu to return to the library overview page.
-
Click Web Content and open the Job Listings folder.
-
Begin editing an article and assign any of the newly added locations (e.g. Morocco, Casablanca).
-
Click Publish. You can now search for the content using the new location category.
Conclusion
Congratulations, you’ve completed Module 8: Headless APIs. Throughout this module, you’ve seen different use cases for using Headless APIs and how a company like Clarity can leverage them to migrate existing data.
Next, let’s explore how Clarity can leverage Liferay’s search tools and capabilities to improve user experience.
Up Next: Module 9: Search
Additional Resources
See official documentation to learn more about using Liferay’s headless APIs: