Record search
2 min
If you haven't gone through the prerequisites and the v2 structure, please have a look at Overview
The recordQuery object is used for searching for records. Use this for retrieving Products, Categories, CMS Pages or your own Custom Entity types when your customer has submitted a search query.
Record search
This is an example to fetch instant auto complete using APIs.
POST
https://{{hostname}}/cs/v2/search
Body Parameters
- idstringrequiredDescription
- typeOfRequeststringrequiredDescription
- querystringrequiredDescription
Request Body (JSON)
{
"recordQueries": [
{
"id": "productSearch",
"typeOfRequest": "SEARCH",
"settings": {
"query": {
"term": "short"
},
"limit": 5,
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-156925593843210765"
]
}
}php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://eucs15v2.ksearchnet.com/cs/v2/search',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"recordQueries": [
{
"id": "productSearch",
"typeOfRequest": "SEARCH",
"settings": {
"query": {
"term": "short"
},
"limit": 5,
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-156925593843210765"
]
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
javascript
var data = "{\n \"recordQueries\": [\n {\n \"id\": \"productSearch\",\n \"typeOfRequest\": \"SEARCH\",\n \"settings\": {\n \"query\": {\n \"term\": \"short\"\n },\n \"limit\": 5,\n \"typeOfRecords\": [\n \"KLEVU_PRODUCT\"\n ]\n }\n }\n ],\n \"context\": {\n \"apiKeys\": [\n \"klevu-156925593843210765\"\n ]\n }\n}";
var xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://eucs15v2.ksearchnet.com/cs/v2/search");
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.send(data);java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "{\n \"recordQueries\": [\n {\n \"id\": \"productSearch\",\n \"typeOfRequest\": \"SEARCH\",\n \"settings\": {\n \"query\": {\n \"term\": \"short\"\n },\n \"limit\": 5,\n \"typeOfRecords\": [\n \"KLEVU_PRODUCT\"\n ]\n }\n }\n ],\n \"context\": {\n \"apiKeys\": [\n \"klevu-156925593843210765\"\n ]\n }\n}");
Request request = new Request.Builder()
.url("https://eucs15v2.ksearchnet.com/cs/v2/search")
.method("POST", body)
.addHeader("Content-Type", "text/plain")
.build();
Response response = client.newCall(request).execute();nodejs
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://eucs15v2.ksearchnet.com/cs/v2/search',
'headers': {
'Content-Type': 'text/plain'
},
body: '{\n "recordQueries": [\n {\n "id": "productSearch",\n "typeOfRequest": "SEARCH",\n "settings": {\n "query": {\n "term": "short"\n },\n "limit": 5,\n "typeOfRecords": [\n "KLEVU_PRODUCT"\n ]\n }\n }\n ],\n "context": {\n "apiKeys": [\n "klevu-156925593843210765"\n ]\n }\n}'
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
200
{
"meta": {
"qTime": 7,
"responseCode": 200
},
"queryResults": [
{
"id": "productSearch",
"meta": {
"qTime": 6,
"noOfResults": 5,
"totalResultsFound": 104,
"typeOfSearch": "WILDCARD_AND",
"offset": 0,
"debuggingInformation": {},
"notificationCode": 1,
"searchedTerm": "short",
"apiKey": "klevu-156925593843210765",
"isPersonalised": false
},
"records": [
{
"discount": "",
"hideGroupPrices": "",
"type": "Shorts",
"itemGroupId": "4384016334910",
"freeShipping": "",
"storeBaseCurrency": "GBP",
"price": "45.00",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-green_main_3ac6ebe5-2c3e-45cf-91cf-ec54de5e5e3a_medium.jpg?v=1575477721",
"currency": "GBP",
"inStock": "yes",
"id": "31366431146046",
"imageHover": "",
"sku": "WSH12-28-Green",
"brand": "KSD",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-green_main_3ac6ebe5-2c3e-45cf-91cf-ec54de5e5e3a_medium.jpg?v=1575477721",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "45.0",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-green",
"tags": "body-hugging, Green, nylon, Running, Short",
"size": "Small",
"name": "Erika Running Short",
"shortDesc": "A great short with a body-hugging design, the Erika Running Short is perfect for runners who prefer a fitted short rather than the traditional baggy variety. • Seafoam pattern running shorts. • Elastic waistband. • Snug fit. • 4''",
"category": "Shorts",
"typeOfRecord": "KLEVU_PRODUCT"
},
{
"discount": "",
"hideGroupPrices": "",
"type": "Shorts",
"itemGroupId": "4384016269374",
"freeShipping": "",
"storeBaseCurrency": "GBP",
"price": "45.00",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-purple_main_c57ce41e-7b0e-4cd2-a0de-18ddb6d2017a_medium.jpg?v=1575477720",
"currency": "GBP",
"inStock": "yes",
"id": "31366431080510",
"imageHover": "",
"sku": "WSH12-28-Purple",
"brand": "KSD",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-purple_main_c57ce41e-7b0e-4cd2-a0de-18ddb6d2017a_medium.jpg?v=1575477720",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "45.0",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-purple",
"tags": "body-hugging, nylon, Red, Running, Short",
"size": "Large",
"name": "Erika Running Short",
"shortDesc": "A great short with a body-hugging design, the Erika Running Short is perfect for runners who prefer a fitted short rather than the traditional baggy variety. • Seafoam pattern running shorts. • Elastic waistband. • Snug fit. • 4''",
"category": "Shorts",
"typeOfRecord": "KLEVU_PRODUCT"
},
{
"discount": "",
"hideGroupPrices": "",
"type": "Shorts",
"itemGroupId": "4384016203838",
"freeShipping": "",
"storeBaseCurrency": "GBP",
"price": "45.00",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-red_main_9999e03f-694d-4f0c-83ab-8c0200029275_medium.jpg?v=1575477719",
"currency": "GBP",
"inStock": "yes",
"id": "31366431014974",
"imageHover": "",
"sku": "WSH12-28-Red",
"brand": "KSD",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-red_main_9999e03f-694d-4f0c-83ab-8c0200029275_medium.jpg?v=1575477719",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "45.0",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-red",
"tags": "body-hugging, nylon, Red, Running, Short",
"size": "Medium",
"name": "Erika Running Short",
"shortDesc": "A great short with a body-hugging design, the Erika Running Short is perfect for runners who prefer a fitted short rather than the traditional baggy variety. • Seafoam pattern running shorts. • Elastic waistband. • Snug fit. • 4''",
"category": "Shorts",
"typeOfRecord": "KLEVU_PRODUCT"
},
{
"discount": "",
"hideGroupPrices": "",
"type": "Shorts",
"itemGroupId": "4384040386622",
"freeShipping": "",
"storeBaseCurrency": "GBP",
"price": "32.50",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh03-black_main_a8796b84-9c70-4146-9c73-2295b0d260a7_medium.jpg?v=1575478122",
"currency": "GBP",
"inStock": "yes",
"id": "31366465781822",
"imageHover": "",
"sku": "MSH03-32-Black",
"brand": "KKE",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh03-black_main_a8796b84-9c70-4146-9c73-2295b0d260a7_medium.jpg?v=1575478122",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "32.5",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://jsv2-shopify-demo.ksearchmisc.com/products/meteor-workout-short-black",
"tags": "black, Machine, Nylon, Relaxed fit, Short, Summer",
"size": "Small",
"name": "Meteor Workout Short",
"shortDesc": "Step into the Meteor Workout Short for an incredibly lightweight fitness experience. Its breathable construction and an inner brief provide additional comfort and support, while the adjustable waistband offers the perfect fit to take you to the fi",
"category": "Shorts",
"typeOfRecord": "KLEVU_PRODUCT"
},
{
"discount": "",
"hideGroupPrices": "",
"type": "Shorts",
"itemGroupId": "4384039665726",
"freeShipping": "",
"storeBaseCurrency": "GBP",
"price": "29.00",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh05-gray_main_0f869cff-09fb-403a-a209-cf092f4d3c1a_medium.jpg?v=1575478112",
"currency": "GBP",
"inStock": "yes",
"id": "31366465060926",
"imageHover": "",
"sku": "MSH05-32-Gray",
"brand": "KSD",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh05-gray_main_0f869cff-09fb-403a-a209-cf092f4d3c1a_medium.jpg?v=1575478112",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "29.0",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://jsv2-shopify-demo.ksearchmisc.com/products/hawkeye-yoga-short-gray",
"tags": "Gray, Machine, Nylon, Relaxed fit, Short, Summer",
"size": "Medium",
"name": "Hawkeye Yoga Short",
"shortDesc": "What more do you need than a sporty yoga short made with organic cotton and a little spandex for mobility? The Hawkeye Yoga Short brings a stylish, standard fit you can sport with confidence outside the studio. • Dark gray shorts with red a",
"category": "Shorts",
"typeOfRecord": "KLEVU_PRODUCT"
}
],
"filters": []
}
]
}Try it here!