Guide
Smart Search
Record search
2min
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.
This is an example to fetch instant auto complete using APIs.
POST
Request
Body Parameters
id
required
String
Every suggestion request must have a unique identifier associated with it. When a result is retrieved, the ID of each query is associated with it's respective response.
typeOfQuery
required
String
The type of suggestion query. Specify 'AUTO_SUGGESTIONS' for typeahead autosuggestion predictions.
query
required
String
The search term or phrase for which the suggestions are retrieved from Klevu Search.
Request Body (JSON)
PHP
JS
Java
Node.js
1var 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}";
2
3var xhr = new XMLHttpRequest();
4xhr.withCredentials = false;
5
6xhr.addEventListener("readystatechange", function() {
7 if(this.readyState === 4) {
8 console.log(this.responseText);
9 }
10});
11
12xhr.open("POST", "https://eucs15v2.ksearchnet.com/cs/v2/search");
13xhr.setRequestHeader("Content-Type", "text/plain");
14
15xhr.send(data);
Responses
200
1{
2 "meta": {
3 "qTime": 7,
4 "responseCode": 200
5 },
6 "queryResults": [
7 {
8 "id": "productSearch",
9 "meta": {
10 "qTime": 6,
11 "noOfResults": 5,
12 "totalResultsFound": 104,
13 "typeOfSearch": "WILDCARD_AND",
14 "offset": 0,
15 "debuggingInformation": {},
16 "notificationCode": 1,
17 "searchedTerm": "short",
18 "apiKey": "klevu-156925593843210765",
19 "isPersonalised": false
20 },
21 "records": [
22 {
23 "discount": "",
24 "hideGroupPrices": "",
25 "type": "Shorts",
26 "itemGroupId": "4384016334910",
27 "freeShipping": "",
28 "storeBaseCurrency": "GBP",
29 "price": "45.00",
30 "toPrice": "",
31 "imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-green_main_3ac6ebe5-2c3e-45cf-91cf-ec54de5e5e3a_medium.jpg?v=1575477721",
32 "currency": "GBP",
33 "inStock": "yes",
34 "id": "31366431146046",
35 "imageHover": "",
36 "sku": "WSH12-28-Green",
37 "brand": "KSD",
38 "startPrice": "",
39 "image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-green_main_3ac6ebe5-2c3e-45cf-91cf-ec54de5e5e3a_medium.jpg?v=1575477721",
40 "deliveryInfo": "",
41 "hideAddToCart": "",
42 "salePrice": "45.0",
43 "swatchesInfo": "",
44 "weight": "",
45 "klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
46 "totalVariants": 0,
47 "groupPrices": "",
48 "url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-green",
49 "tags": "body-hugging, Green, nylon, Running, Short",
50 "size": "Small",
51 "name": "Erika Running Short",
52 "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''",
53 "category": "Shorts",
54 "typeOfRecord": "KLEVU_PRODUCT"
55 },
56 {
57 "discount": "",
58 "hideGroupPrices": "",
59 "type": "Shorts",
60 "itemGroupId": "4384016269374",
61 "freeShipping": "",
62 "storeBaseCurrency": "GBP",
63 "price": "45.00",
64 "toPrice": "",
65 "imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-purple_main_c57ce41e-7b0e-4cd2-a0de-18ddb6d2017a_medium.jpg?v=1575477720",
66 "currency": "GBP",
67 "inStock": "yes",
68 "id": "31366431080510",
69 "imageHover": "",
70 "sku": "WSH12-28-Purple",
71 "brand": "KSD",
72 "startPrice": "",
73 "image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-purple_main_c57ce41e-7b0e-4cd2-a0de-18ddb6d2017a_medium.jpg?v=1575477720",
74 "deliveryInfo": "",
75 "hideAddToCart": "",
76 "salePrice": "45.0",
77 "swatchesInfo": "",
78 "weight": "",
79 "klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
80 "totalVariants": 0,
81 "groupPrices": "",
82 "url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-purple",
83 "tags": "body-hugging, nylon, Red, Running, Short",
84 "size": "Large",
85 "name": "Erika Running Short",
86 "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''",
87 "category": "Shorts",
88 "typeOfRecord": "KLEVU_PRODUCT"
89 },
90 {
91 "discount": "",
92 "hideGroupPrices": "",
93 "type": "Shorts",
94 "itemGroupId": "4384016203838",
95 "freeShipping": "",
96 "storeBaseCurrency": "GBP",
97 "price": "45.00",
98 "toPrice": "",
99 "imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-red_main_9999e03f-694d-4f0c-83ab-8c0200029275_medium.jpg?v=1575477719",
100 "currency": "GBP",
101 "inStock": "yes",
102 "id": "31366431014974",
103 "imageHover": "",
104 "sku": "WSH12-28-Red",
105 "brand": "KSD",
106 "startPrice": "",
107 "image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/wsh12-red_main_9999e03f-694d-4f0c-83ab-8c0200029275_medium.jpg?v=1575477719",
108 "deliveryInfo": "",
109 "hideAddToCart": "",
110 "salePrice": "45.0",
111 "swatchesInfo": "",
112 "weight": "",
113 "klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
114 "totalVariants": 0,
115 "groupPrices": "",
116 "url": "https://jsv2-shopify-demo.ksearchmisc.com/products/erika-running-short-red",
117 "tags": "body-hugging, nylon, Red, Running, Short",
118 "size": "Medium",
119 "name": "Erika Running Short",
120 "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''",
121 "category": "Shorts",
122 "typeOfRecord": "KLEVU_PRODUCT"
123 },
124 {
125 "discount": "",
126 "hideGroupPrices": "",
127 "type": "Shorts",
128 "itemGroupId": "4384040386622",
129 "freeShipping": "",
130 "storeBaseCurrency": "GBP",
131 "price": "32.50",
132 "toPrice": "",
133 "imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh03-black_main_a8796b84-9c70-4146-9c73-2295b0d260a7_medium.jpg?v=1575478122",
134 "currency": "GBP",
135 "inStock": "yes",
136 "id": "31366465781822",
137 "imageHover": "",
138 "sku": "MSH03-32-Black",
139 "brand": "KKE",
140 "startPrice": "",
141 "image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh03-black_main_a8796b84-9c70-4146-9c73-2295b0d260a7_medium.jpg?v=1575478122",
142 "deliveryInfo": "",
143 "hideAddToCart": "",
144 "salePrice": "32.5",
145 "swatchesInfo": "",
146 "weight": "",
147 "klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
148 "totalVariants": 0,
149 "groupPrices": "",
150 "url": "https://jsv2-shopify-demo.ksearchmisc.com/products/meteor-workout-short-black",
151 "tags": "black, Machine, Nylon, Relaxed fit, Short, Summer",
152 "size": "Small",
153 "name": "Meteor Workout Short",
154 "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",
155 "category": "Shorts",
156 "typeOfRecord": "KLEVU_PRODUCT"
157 },
158 {
159 "discount": "",
160 "hideGroupPrices": "",
161 "type": "Shorts",
162 "itemGroupId": "4384039665726",
163 "freeShipping": "",
164 "storeBaseCurrency": "GBP",
165 "price": "29.00",
166 "toPrice": "",
167 "imageUrl": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh05-gray_main_0f869cff-09fb-403a-a209-cf092f4d3c1a_medium.jpg?v=1575478112",
168 "currency": "GBP",
169 "inStock": "yes",
170 "id": "31366465060926",
171 "imageHover": "",
172 "sku": "MSH05-32-Gray",
173 "brand": "KSD",
174 "startPrice": "",
175 "image": "https://cdn.shopify.com/s/files/1/0116/9457/1582/products/msh05-gray_main_0f869cff-09fb-403a-a209-cf092f4d3c1a_medium.jpg?v=1575478112",
176 "deliveryInfo": "",
177 "hideAddToCart": "",
178 "salePrice": "29.0",
179 "swatchesInfo": "",
180 "weight": "",
181 "klevu_category": "KLEVU_PRODUCT;Products;;Shorts @ku@kuCategory@ku@",
182 "totalVariants": 0,
183 "groupPrices": "",
184 "url": "https://jsv2-shopify-demo.ksearchmisc.com/products/hawkeye-yoga-short-gray",
185 "tags": "Gray, Machine, Nylon, Relaxed fit, Short, Summer",
186 "size": "Medium",
187 "name": "Hawkeye Yoga Short",
188 "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",
189 "category": "Shorts",
190 "typeOfRecord": "KLEVU_PRODUCT"
191 }
192 ],
193 "filters": []
194 }
195 ]
196}
1<iframe src="https://codesandbox.io/embed/klevu-api-sendbox-4ktfrp?fontsize=14&hidenavigation=0&theme=dark&view=preview&initialpath=?payload=recordSearch"
2 style="width:100%; height:550px; border:0; border-radius: 4px; overflow:hidden;"
3 title="klevu_api sendbox"
4 allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
5 sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
6
7 ></iframe>
Updated 30 Oct 2023
Did this page help you?