Example API Calls
To give users more insight on how to use Experience API, the following samples are provided.
Sample process flow: Login, accessing content, and logout
-
Call Examples
Before sending an API call, users need to get the UUID of the content they want to access out of HCL Digital Experience 9.5. Here are the steps to follow:
- Log in to HCL Digital Experience 9.5 using
http://<PORTAL_HOST>:<PORTAL_PORT>/wps/portal
. -
Go to Web Content Authoring.
Note
- If you have Practitioner Studio enabled, navigate to Web Content > Authoring.
- If you do not have Practitioner Studio configured in your Digital Experience 9.5 deployment, navigate to Content > Authoring.
-
From Authoring, click on the Web Content > Content > Articles. A list of articles is displayed.
- Click on any article and select Properties > Content Properties.
- Look for UUID value. If not available click on More > Show More Fields.
-
Copy the UUID value. Use the UUID obtained in the previous process and use it to access content and logout flow:
- Open HCL Experience API explorer using
http://<HOST>:<PORT>/dx/api/core/v1/explorer
(e.g. 'http://127.0.0.1:3000/dx/api/core/v1/explorer`). - Execute Login API endpoint
auth/login
by entering a valid username and password. -
Once the login is successful, execute the following content ID endpoint to fetch content based on the content ID:
/{accessType}/webcontent/contents/{contentId}
-
Pass the UUID value copied earlier as
contentID
. The json in the request body will need to be update to have a correct content name. For example:{"contentName": "Sample Article"}
-
Verify if the content payload is received. It should contain information about the article you wanted to access.
- To log out of HCL Experience API, execute the Logout API command.
- Open HCL Experience API explorer using
- Log in to HCL Digital Experience 9.5 using
Sample scripts: Login, Get roles, Get roles with authentication
Open the HCL Experience API GraphQL URL: http://localhost:4000/dx/api/core/v1/graphql.
See example result:
-
Copy the scripts below and place those in the left panel of the HCL Experience API interface, then click on the execute button:
-
Login Script
mutation { authLogin(authLoginInput:{username: "wpsadmin", password:"wpsadmin"}){ message statusCode } }
-
Get Roles script (Without authentication)
query{ accessGetRoles(accessType: dxrest, resourceId: "hcl.portal.hiddenpages"){ startIndex itemsPerPage totalResults } }
-
Get Roles script (With authentication) - Refer to the screenshot below to retrieve the cookie and pass using the HCL Experience API.
query{ accessGetRoles(accessType: dxmyrest, resourceId: "hcl.portal.hiddenpages", cookie :"LtpaToken2=EF/ 32eLqVkB8DmPoF2Oa7AK82OuP7UwVKejVMJzNiVGJ6DtGWzQjm/ 2i2V8aFf8hbNnxzqBhiYvg27qavPehNl+42/ iCleAdiGhZsgpPFNTLEbjlj+GAhxl+VCU1hhU78hOT2xDHkvjRz74eU6JU5RapIK3MZd yHlI4QzQggg+t7f6Hzq8TY/gWEPlAKio+v74i7H4Snj28YYikDzLwKbqh/ 0c3uORdCCcrjtJJB6Jv59HuUyeeFIAA1DbKj5vr2QBy9r4b6IgdtLyZJqNK2pASGzOrzJ myckF+d65pG56mXDxPrQRsr1ccmIXid+jLu50GziCVtI/DC+SYKkTe/ +FLFIFzdbuzyyCxiVo+G91HTCSdfuBzpNFEhNODCBPE5OJtD00L2yEhugbDulLFJid9C RI3qW7LIwnVrs66Bh7/G0ehTJ7+cn/YKqhc/EoV/ hIuD5RgJTIQmFmRUISzGKfqaEsDs2W/ LMPM3fVxbeW9+2QvlHwWgqfK9A96u14Gvfc991Q/ iyJRmMj6tLmf2qAzyBTJKpoZkMt6FezkxUExNzzgf6ZvYa8s8uMV5pzsMhUX/ 7s8SfkrwxJXdCYP75xUH/xvvkW+J5w9pm0uSJsPgj6Er8RtqUXRWvACBZ51T/ 6VUl8yXcJpuuVoGROl8IIFZz8xCkQuqABHc8cWjdM8="){ startIndex itemsPerPage totalResults } }
-
Enabling the use of SVG files in DAM API
Follow the steps below to enable uploading an SVG file in DAM API:
-
In any REST API Client tool, log in to Ring API via:
POST - https://<domain>/dx/api/core/v1/auth/login
-
Enter the username and password:
{ "username": "wpsadmin", "password": "wpsadmin" }
-
Access GET mediatypes to verify if the SVG file type is available and enabled by going to the following URL:
https://<domain>/dx/api/dam/v1/mediatypes
Here is an example of a disabled SVG entry:
{ "id": "973422667d9d4b9ed6d668db017ba049", "mimeType": "image/svg+xml", "extensions": [ "svg" ], "mediaTypeGroupId": "59b514174bffe4ae402b3d63aad79fe0", "created": "2023-04-19T06:45:42.088Z", "updated": "2023-04-19T14:05:28.270Z", "enabled": false, "self": "/mediatypes/973422667d9d4b9ed6d668db017ba049", "type": "image" }
-
Do a PATCH to update the enable flag to True for SVG files:
PATCH - https://<domain>/dx/api/dam/v1/mediatypes/<id>
Example: https://dx.com/dx/api/dam/v1/mediatypes/973422667d9d4b9ed6d668db017ba049,
{ "enabled": true }
-
Verify if the SVG is enabled by repeating Step 3. If enabled, proceed with uploading SVG files in DAM.
You can also verify in DAM > Settings if the SVG file type is enabled.
Adding a new mime type in DAM
Refer to the following steps to enable uploading an SVG file in DAM API:
-
In any REST API Client Tool, log in to Ring API via:
POST - https://<domain>/dx/api/core/v1/auth/login
The payload of the POST request should look like this:
{ "username": "<userId>" "password": "<password>" }
-
Access GET mediatypegroups to get the media type group into which the new media type should be added. Find the id for image media type group.
https://<domain>/dx/api/dam/v1/mediatypegroups
-
Do a POST request to the following endpoint to add a new mime type:
https://<domain>/dx/api/dam/v1/mediatypes
To add a new webp file type, use a payload similar to:
[{ "mimeType": "image/webp", "extensions": ["webp"], "mediaTypeGroupId": "<mediaTypeGroupId from step #3>" }]
If you want to configure renditions for the newly added mime type, refer to Extensibility configuration.
HCLSoftware U learning materials
For an introduction and a demo on how to use Experience API, go to Experience API. To try it out yourself, refer to Experience API Lab and corresponding Experience API Lab Resources.