Calling the Search and Recommendation API
Sitecore Discover supports both HTTP and HTTPS protocols for the Search and Recommendation API. You can access the API using the GET or POST methods.
The API accepts requests in the form of JSON objects. All information of inquiry to the API must be in key data. The value of the key can either be a JSON string or a URL encoded JSON string.
API URL
You can get the API URL in the Customer Engagement Console, in Developer Resources, on the API Access tab.
API methods
You use the GET or POST method to send requests to the Sitecore Discover Search and Recommendation API.
The following table describes the required key:
|
Key |
Data type |
Description |
|---|---|---|
|
|
<JSON string> OR <url encoded JSON string> |
A JSON string that represents the request. If passed as a |
Examples
The following shows an example of a GET request to the Search and Recommend API:
GET {API_URL}?data={<your_key_value_data>}The following shows an example of a POST request to the Search and Recommend API:
POST {API_URL}
{
"data": "{<your_key_value_data>}"
}The following shows an example in Python using the Requests library:
import requests
import json
url = 'API_URL'
data = {
"data": '{"query": {"keyphrase": ["example"]},"content": {}}'
}
response = requests.post(url, params=data)
print json.loads(response.text)Reading responses
Within the content response object, there is a nested product and then value object. You can get the information you need to populate one product slot from the keys and values in the value object.
The sample responses for search page, product listing page, recommendation widget, and preview search widget integration have more information.
The following code snippet shows a partial sample response with the content response object:
{
"content": {
"product": {
"total_item": 1131,
"n_item": 1,
"value": [{
"division_name": "CALI",
"prod_color_count": "5",
"color": "SLT",
"price": "65.00",
"category_names": [
"Women",
"Breathable",
"Sandals",
"Shoes",
"Website Premieres",
"Stretch Fit",
"Arch Fit",
"Women-shop-all"
],
"sku_url": "/women/shoes/arch-fit---city-catch/119236_SLT.html",
"swatch_index": 0,
"variation_product_id": "119236_SLT",
"brands": [
"Arch Fit"
],
"swatch": [{
"swatch_landing_url": "/women/shoes/<URL>.html",
"sku_url": "/women/shoes/<URL>.html",
"color": "SLT",
"swatch_image_url": "https://<url>",
"swatch_style": "#000000",
"primary_color": "BLUE",
"sku_image_url": "https://"
}],
"id": 997986357,
"webwidth_flag": "0",
"size": "7.0",
"sku": "195204519462",
"skuid": 1816486109,
"color_swatch_show_count": 2,
"name": "Women's Arch Fit - City Catch",
"color_swatch": [{
"swatch_landing_url": "/women/shoes/<url>.html",
"color": "SLT",
"swatch_style": "#000000",
"primary_color": "BLUE",
"swatch_image_url": ""
}],
"style_num": "119236",
"original_name": "Arch Fit - City Catch ",
"url": "/women/shoes/<url>",
"image_url": "https://<url>",
"final_price": "65.00",
"primary_color": "BLUE",
"product_group": "119236",
"brand": "Arch Fit",
"sku_image_url": "https://<url>",
"thumbnail_image_url": "https://<url>"
}]
}
}
}