XML API
The Klevu Indexing API is organized around REST. Our API has predictable resource-oriented URLs, accepts XML request bodies, returns XML-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
Every record (e.g. a product, category, cms page etc.) sent to Klevu is maintained in a dedicated index for the respective store. The Indexing API is used for adding, updating or deleting records from this index.
The Indexing API requires that you first authenticate yourself to the Klevu servers. As a result of this authentication, you are provided with a Session ID which you can use for subsequent requests to the Klevu servers.
API Key & Endpoint
You must have a Klevu Search account to use the Klevu API. Please access the Shop Info section of your Klevu Merchant Centre to retrieve the following credentials.
- REST API Key (private key) for submitting data to be indexed, eg. abcdefoobar==.
- Product Synchronization URL for submitting data to be indexed, eg. rest.klevu.com.
What is a Record?
With Klevu a record can be a Product, a Category page or a CMS page that you want to index and make available in search results. It can also be a custom record type such as a Store or Recipe or something like that.
When you submit a record for addition or update, you must submit the record with all of its details provided. A list of mandatory and optional fields is provided below. When you submit a record for deletion, however, you only need to submit its unique ID.
Requesting a Session ID
Use this call to authenticate yourself to the Klevu Indexing servers. In the response, you will be provided with a Session ID which you should use for all subsequent requests to the Klevu servers.
You will need your REST API Key and Product Synchronization URL. Please refer to the Prerequisites section for more information.
curl --location --request POST 'http://rest2.ksearchnet.com/rest/service/startSession' \
--header 'Authorization: abcdefoobar=='Adding New Records
You must provide each record in full, including all mandatory parameters for every record you submit.
Prerequisites: You will also need a Session ID, please see the section above on Requesting a Session ID.
curl --location --request POST 'https://<productSynchronizationURL>/rest/service/addRecords' \
--header 'Content-Type: application/xml' \
--data-raw '<?xml version="1.0" encoding="UTF-8" ?>
<request>
<sessionId>Your-Session-ID</sessionId>
<records>
<record>
<pairs>
<!-- IDs -->
<pair>
<key>id</key>
<value>123-ABC</value>
</pair>
<pair>
<key>itemGroupId</key>
<value>123</value>
</pair>
<!-- Product Information -->
<pair>
<key>sku</key>
<value>SKU-123-ABC</value>
</pair>
<pair>
<key>name</key>
<value>My Product Name</value>
</pair>
<pair>
<key>inStock</key>
<value>yes</value>
</pair>
<pair>
<key>url</key>
<value>https://your-website.com/products/123.html</value>
</pair>
<pair>
<key>image</key>
<value>https://your-website.com/images/products/123-abc.jpg</value>
</pair>
<pair>
<key>imageHover</key>
<value>https://your-website.com/images/products/hover/123-abc.jpg</value>
</pair>
<!-- Product Descriptions -->
<pair>
<key>shortDesc</key>
<value>My Short Description</value>
</pair>
<pair>
<key>desc</key>
<value>My Longer Description</value>
</pair>
<!-- Prices -->
<pair>
<key>currency</key>
<value>GBP</value>
</pair>
<pair>
<key>price</key>
<value>150.00</value>
</pair>
<pair>
<key>salePrice</key>
<value>100.00</value>
</pair>
<pair>
<key>startPrice</key>
<value>50.00</value>
</pair>
<pair>
<key>toPrice</key>
<value>200.00</value>
</pair>
<pair>
<key>otherPrices</key>
<value>price_GBP:150.00;price_USD:200.00;salePrice_GBP:100.00;salePrice_USD:150.00;startPrice_GBP:50.00;startPrice_USD:100.00;toPrice_GBP:200.00;toPrice_USD:300.00;price_GBP-test_group_1:100.00;price_USD-test_group_1:150.00;salePrice_GBP-test_group_1:80.00;salePrice_USD-test_group_1:100.00;startPrice_GBP-test_group_1:30.00;startPrice_USD-test_group_1:50.00;toPrice_GBP-test_group_1:180.00;toPrice_USD-test_group_1:200.00;price_GBP-test_group_2:90.00;price_USD-test_group_2:140.00;salePrice_GBP-test_group_2:70.00;salePrice_USD-test_group_2:90.00;startPrice_GBP-test_group_2:20.00;startPrice_USD-test_group_2:40.00;toPrice_GBP-test_group_2:170.00;toPrice_USD-test_group_2:190.00</value>
</pair>
<pair>
<key>groupPrices</key>
<value>test_group_1:Test Group 1:80.00;test_group_2:Test Group 2:70.00</value>
</pair>
<!-- Categorisation -->
<pair>
<key>category</key>
<value>Sub Category A-2;Sub Category B-2</value>
</pair>
<pair>
<key>listCategory</key>
<value>KLEVU_PRODUCT;;Category A;Sub Category A-1;Sub Category A-2;;Category B;Sub Category B-1;Sub Category B-2;;test_group_1;;test_group_2</value>
</pair>
<!-- Attributes -->
<pair>
<key>other</key>
<value>color:Colour:red;occasion:Occasion:Christmas,Evening Wear</value>
</pair>
<pair>
<key>otherAttributeToIndex</key>
<value>brand:Brand Name:Nike,Adidas;gtin:GTIN:123456789</value>
</pair>
<pair>
<key>rating</key>
<value>3.5</value>
</pair>
<pair>
<key>rating_count</key>
<value>10</value>
</pair>
<pair>
<key>tags</key>
<value>keyword 1,keyword 2</value>
</pair>
<!-- Swatches -->
<pair>
<key>variantId1</key>
<value>123-ABC</value>
</pair>
<pair>
<key>variantColor1</key>
<value>Red</value>
</pair>
<pair>
<key>variantSwatchImage1</key>
<value>https://your-website.com/images/swatches/red.jpg</value>
</pair>
<pair>
<key>variantImage1</key>
<value>https://your-website.com/images/products/456-abc.jpg</value>
</pair>
<pair>
<key>variantId2</key>
<value>123-BCD</value>
</pair>
<pair>
<key>variantColor2</key>
<value>White</value>
</pair>
<pair>
<key>variantSwatchImage2</key>
<value>https://your-website.com/images/swatches/white.jpg</value>
</pair>
<pair>
<key>variantImage2</key>
<value>https://your-website.com/images/products/123-def.jpg</value>
</pair>
<!-- Miscellaneous -->
<pair>
<key>boostingAttribute</key>
<value>5</value>
</pair>
<pair>
<key>additionalDataToReturn</key>
<value>{"some_arbitrary": "data to return"}</value>
</pair>
</pairs>
</record>
</records>
</request>'Updating Existing Records
You must provide each record in full, including all mandatory parameters for every record you submit.
Prerequisites: You will also need a Session ID, please see the section above on Requesting a Session ID.
curl --location --request POST 'https://<productSynchronizationURL>/rest/service/updateRecords' \
--header 'Content-Type: application/xml' \
--data-raw '<?xml version="1.0" encoding="UTF-8" ?>
<request>
<sessionId>Your-Session-ID</sessionId>
<records>
<record>
<pairs>
<!-- IDs -->
<pair>
<key>id</key>
<value>123-ABC</value>
</pair>
<pair>
<key>itemGroupId</key>
<value>123</value>
</pair>
<!-- Product Information -->
<pair>
<key>sku</key>
<value>SKU-123-ABC</value>
</pair>
<pair>
<key>name</key>
<value>My Product Name</value>
</pair>
<pair>
<key>inStock</key>
<value>yes</value>
</pair>
<pair>
<key>url</key>
<value>https://your-website.com/products/123.html</value>
</pair>
<pair>
<key>image</key>
<value>https://your-website.com/images/products/123-abc.jpg</value>
</pair>
<pair>
<key>imageHover</key>
<value>https://your-website.com/images/products/hover/123-abc.jpg</value>
</pair>
<!-- Product Descriptions -->
<pair>
<key>shortDesc</key>
<value>My Short Description</value>
</pair>
<pair>
<key>desc</key>
<value>My Longer Description</value>
</pair>
<!-- Prices -->
<pair>
<key>currency</key>
<value>GBP</value>
</pair>
<pair>
<key>price</key>
<value>150.00</value>
</pair>
<pair>
<key>salePrice</key>
<value>100.00</value>
</pair>
<pair>
<key>startPrice</key>
<value>50.00</value>
</pair>
<pair>
<key>toPrice</key>
<value>200.00</value>
</pair>
<pair>
<key>otherPrices</key>
<value>price_GBP:150.00;price_USD:200.00;salePrice_GBP:100.00;salePrice_USD:150.00;startPrice_GBP:50.00;startPrice_USD:100.00;toPrice_GBP:200.00;toPrice_USD:300.00;price_GBP-test_group_1:100.00;price_USD-test_group_1:150.00;salePrice_GBP-test_group_1:80.00;salePrice_USD-test_group_1:100.00;startPrice_GBP-test_group_1:30.00;startPrice_USD-test_group_1:50.00;toPrice_GBP-test_group_1:180.00;toPrice_USD-test_group_1:200.00;price_GBP-test_group_2:90.00;price_USD-test_group_2:140.00;salePrice_GBP-test_group_2:70.00;salePrice_USD-test_group_2:90.00;startPrice_GBP-test_group_2:20.00;startPrice_USD-test_group_2:40.00;toPrice_GBP-test_group_2:170.00;toPrice_USD-test_group_2:190.00</value>
</pair>
<pair>
<key>groupPrices</key>
<value>test_group_1:Test Group 1:80.00;test_group_2:Test Group 2:70.00</value>
</pair>
<!-- Categorisation -->
<pair>
<key>category</key>
<value>Sub Category A-2;Sub Category B-2</value>
</pair>
<pair>
<key>listCategory</key>
<value>KLEVU_PRODUCT;;Category A;Sub Category A-1;Sub Category A-2;;Category B;Sub Category B-1;Sub Category B-2;;test_group_1;;test_group_2</value>
</pair>
<!-- Attributes -->
<pair>
<key>other</key>
<value>color:Colour:red;occasion:Occasion:Christmas,Evening Wear</value>
</pair>
<pair>
<key>otherAttributeToIndex</key>
<value>brand:Brand Name:Nike,Adidas;gtin:GTIN:123456789</value>
</pair>
<pair>
<key>rating</key>
<value>3.5</value>
</pair>
<pair>
<key>rating_count</key>
<value>10</value>
</pair>
<pair>
<key>tags</key>
<value>keyword 1,keyword 2</value>
</pair>
<!-- Swatches -->
<pair>
<key>variantId1</key>
<value>123-ABC</value>
</pair>
<pair>
<key>variantColor1</key>
<value>Blue</value>
</pair>
<pair>
<key>variantSwatchImage1</key>
<value>https://your-website.com/images/swatches/blue.jpg</value>
</pair>
<pair>
<key>variantImage1</key>
<value>https://your-website.com/images/products/123-abc.jpg</value>
</pair>
<pair>
<key>variantId2</key>
<value>123-BCD</value>
</pair>
<pair>
<key>variantColor2</key>
<value>White</value>
</pair>
<pair>
<key>variantSwatchImage2</key>
<value>https://your-website.com/images/swatches/white.jpg</value>
</pair>
<pair>
<key>variantImage2</key>
<value>https://your-website.com/images/products/123-def.jpg</value>
</pair>
<!-- Miscellaneous -->
<pair>
<key>boostingAttribute</key>
<value>5</value>
</pair>
<pair>
<key>additionalDataToReturn</key>
<value>{"some_arbitrary": "data to return"}</value>
</pair>
</pairs>
</record>
</records>
</request>'Deleting Existing Records
You must provide the unique IDs of the records you wish to delete.
Prerequisites: You will also need a Session ID, please see the section above on Requesting a Session ID.
curl --location --request POST 'https://<productSynchronizationURL>/rest/service/deleteRecords' \
--header 'Content-Type: application/xml' \
--data-raw '<?xml version="1.0" encoding="UTF-8" ?>
<request>
<sessionId>Your-Session-ID</sessionId>
<records>
<record>
<pairs>
<!-- IDs -->
<pair>
<key>id</key>
<value>123-ABC</value>
</pair>
</pairs>
</record>
</records>
</request>'