Our Blog > Blog Detail

Web Content Viewer- Asponte Custom Skin


Unraveling the mysteries of Portal Search REST API - Part 1

  • Created By: Maria Rauba
  • Updated: May 4, 2021

Recently I needed to use the Search REST API for a project and IBM's documentation in the wiki is a bit confusing.

The wiki documentation is here:
8.5:  https://help.hcltechsw.com/digital-experience/8.5/search-rest-api/constraints-spec.html

8.0: link is no longer available

I found the 8.0 documentation to be more clear about the syntax and the examples were better especially for the Constraints.   For example the 8.0 documentation clearly shows that the syntax is JSON:

Syntax: constraint={"type": "field", "id": "field_id", "values": ["fieldValue1", "fieldValue2"]}

whereas the 8.5 documentation does not:
Syntax: constraint=typefieldidfield_idvalues[fieldValue1,fieldValue2]

An excellent example and write-up on using the REST Search API can be found here:  https://support.hcltechsw.com/csm?id=kb_article&sys_id=f2cfbcefdbc2dc5055f38d6d13961935

I installed this Explorative Search solution and learned a lot about how the Constraints and Facets APIs works.  You can use developer tools to watch the network requests and see very clear examples of how to formulate your search request.  For example, if you choose the Unix tag and the Information Management WCM category, then the following request would be generated :

http://yourserver.com/wps/mycontenthandler/!ut/p/digest!0RUgNCd8_JJOULgZCGb6jA/searchfeed/search?sortKey=RatingAverage&constraint={"type":"category","id":"facets","values":["tag/unix"]}&constraint={"type":"category","id":"facets","values":["category/Information Management"]}&sortOrder=desc&facet={"id": "tag", "count": "ALL", "sortOrder": "DESC"}&facet={"id": "category", "count": "ALL", "sortOrder": "DESC"}&index=Default Search Service::/opt/IBM/WebSphere/wp_profile/PortalServer/collections/IBMExplorativeSearch&query=*&start=0&results=10

One thing to note is that 'category' for the type in the constraint part of the request means 'category' in a general sense, NOT the WCM category.  Also, it is a category used in a facet.

The documentation gives examples like:
constraint={"type": "category", "values":["Tag/tag1","Tag/tag2"]} 

however as you can see in the Explorative search example, the constraint with a type of 'category' needs an "id" value:


If you omit the "id" value, you will get the following error:

<message>parameter "constraint" has an invalid value</message>


So as you can see the documentation is unclear or inaccurate on how to do the REST API requests.

In the next part of this blog, I'll reveal more mysteries on how the facets work and how to do facets on custom metadata.

Contact Form- Asponte Custom Skin


Contact Us


Call Us 888-926-9434
Complementary Content