Calling the Search and Recommendation API
In Sitecore Search, HTTPS protocol is required when using the Search and Recommendation API. The API accepts requests in JSON format.
API URL and methods
You can get the API URL in Sitecore Search, in the Developer Resources section, on the API Access tab.
Use the POST method to send requests to the Search and Recommendation API.
Authentication
You must authenticate to access Sitecore Search REST APIs. Use an API key or access token in the request header.
Mandatory objects
When you send requests to the API, you must include these objects to get a response:
rfk.domainId- add this to the header of your request to specify the domain for which you want to make the request.widget.items.rfkd_id- add this key to specify therfkidof the widget you want to call.widget.items.entity- add this key to specify the entity you want to use for this request.context.locale- If you have a multi-locale domain, add this object to specify the country and language you want to use for the results.
Recommended object
When you send requests to the API, we recommend that you add the following object:
context.user.uuid- an anonymous unique identifier of the visitor who visits the page. Add this object so that Sitecore Search can give your visitors relevant search results. If you do not pass the uuid, the search results you see are not tailored to that specific visitor. To learn how to generate a uuid, see Using a UUID to track site visitors.
If your custom UUID does not follow the above format, ensure that your custom free-form ID is passed in context.user.user_id instead of context.user.uuid in your Search request.
Sample request
The following is a sample POST request to the Search and Recommendation API to get content for the key phrase cloud computing:
Error Codes
The following table lists common errors that you might encounter when calling Sitecore Search APIs with an API key or access token.
Table 1. Error Codes
| Status code | Error | Possible cause | Resolution |
|---|---|---|---|
| 401 Unauthorized | {"message":"Unauthorized"} | The access token is missing, invalid, malformed, or expired. The Authorization header might be missing. | Verify that you are sending a valid API key or bearer token. If the token has expired, generate a new access token. |
| --- | --- | --- | --- |
| 403 Forbidden | Forbidden response | The credentials do not have permission to access the requested API. This can occur when the required scope is not assigned to the API key or token. Some scope-related issues currently return a 401 response instead of 403. | Verify that the API key includes the required scopes and generate a new access token if necessary. |
| 404 Domain not found | domain_id_not_found | The domain ID in the request does not exist or belongs to a different environment. | Verify that you are using the correct domain ID and endpoint for the target environment. |
| 429 Too Many Requests | Rate limit exceeded | Too many requests were sent in a short period of time. | Reduce request volume and retry according to your organization's retry policy. |
| 5xx Server Error | Internal server error or service unavailable | A temporary service issue occurred. | Retry the request according to your organization's retry policy. If the issue persists, contact Sitecore Support. |