Guide
Smart Recommendations
Recently Viewed
2min
If you haven't gone through the prerequisites and the v2 structure, please have a look at Overview
Klevu can power a recommendation banner showcasing any products which the customer has recently viewed. The most common placements for this banner type are:
Homepage: Recently Viewed By You Show a recommendation banner with products the current customer has recently viewed.
The end-point is used for retrieving recently viewed product recommendations.
POST
Request
Body Parameters
typeOfRequest
required
String
For this recommendation type, please specify SEARCH.
customANDQuery
required
String
Here we make a custom query to Klevu, since we know exactly which records we expect in the response. Specify the IDs of all of the products your customer has recently viewed, separated by OR
topIds
optional
Array
Use this field to specify the order the results should be returned, with the most recently viewed product coming first.
Request Body (JSON)
PHP
JS
Java
Node.js
1<?php
2
3$curl = curl_init();
4
5curl_setopt_array($curl, array(
6 CURLOPT_URL => 'https://eucs19v2.ksearchnet.com/cs/v2/search',
7 CURLOPT_RETURNTRANSFER => true,
8 CURLOPT_ENCODING => '',
9 CURLOPT_MAXREDIRS => 10,
10 CURLOPT_TIMEOUT => 0,
11 CURLOPT_FOLLOWLOCATION => true,
12 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13 CURLOPT_CUSTOMREQUEST => 'POST',
14 CURLOPT_POSTFIELDS =>'{
15 "recordQueries": [
16 {
17 "id": "recsRecentlyViewed",
18 "typeOfRequest": "SEARCH",
19 "settings": {
20 "customANDQuery":"(id:\\"34322453430403\\" OR id:\\"34322423840899\\")",
21 "topIds": [
22 {
23 "key": "id",
24 "value": "34322453430403"
25 },
26 {
27 "key": "id",
28 "value": "34322423840899"
29 }
30 ],
31 "typeOfRecords": [
32 "KLEVU_PRODUCT"
33 ]
34 }
35 }
36 ],
37 "context": {
38 "apiKeys": [
39 "klevu-158755634955912036"
40 ]
41 }
42}',
43 CURLOPT_HTTPHEADER => array(
44 'Content-Type: application/json'
45 ),
46));
47
48$response = curl_exec($curl);
49
50curl_close($curl);
51echo $response;
Responses
200
1{
2 "meta": {
3 "qTime": 5,
4 "responseCode": 200
5 },
6 "queryResults": [
7 {
8 "id": "recsRecentlyViewed",
9 "meta": {
10 "qTime": 3,
11 "noOfResults": 12,
12 "totalResultsFound": 2,
13 "typeOfSearch": "WILDCARD_AND",
14 "offset": 0,
15 "debuggingInformation": {},
16 "notificationCode": 1,
17 "searchedTerm": "*",
18 "apiKey": "klevu-158755634955912036",
19 "isPersonalised": false
20 },
21 "records": [
22 {
23 "color": "White Hoodie thick",
24 "discount": "",
25 "hideGroupPrices": "",
26 "itemGroupId": "5192753152131",
27 "freeShipping": "",
28 "storeBaseCurrency": "EUR",
29 "price": "56.68",
30 "toPrice": "",
31 "imageUrl": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797420_medium.jpg?v=1611184206&vid=34322452512899,34322452971651,34322453430403,34322471256195,34322471551107,34322471846019,34322472173699",
32 "currency": "EUR",
33 "inStock": "yes",
34 "id": "34322453430403",
35 "imageHover": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797422_medium.jpg?v=1611184206&vid=34322466177155,34322466603139,34322466930819,34322467192963,34322467586179,34322467946627,34322468339843",
36 "sku": "30504298-white-hoodie-thick-asian-m",
37 "brand": "klevu-personalisation-demo",
38 "basePrice": "56.68",
39 "startPrice": "48.48",
40 "image": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797420_medium.jpg?v=1611184206&vid=34322452512899,34322452971651,34322453430403,34322471256195,34322471551107,34322471846019,34322472173699",
41 "deliveryInfo": "",
42 "hideAddToCart": "",
43 "salePrice": "56.68",
44 "swatchesInfo": "variantColor1:Black Hoodie thin ;;;; variantColor3:Blue Hoodie thick ;;;; variantColor2:White Hoodie thick ;;;; variantColor5:White Hoodie thin ;;;; variantColor4:Black Hoodie thick ;;;; variantColor6:Yellow Hoodie thin ;;;; variantImage6:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797423_medium.jpg?v=1611184258&vid=16847225487491 ;;;; variantImage3:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797419_medium.jpg?v=1611184206&vid=16847185313923 ;;;; variantId6:34322463555715 ;;;; variantImage2:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797420_medium.jpg?v=1611184206&vid=16847185510531 ;;;; variantImage5:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797424_medium.jpg?v=1611184206&vid=16847190851715 ;;;; variantId4:34322456838275 ;;;; variantImage4:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797418_medium.jpg?v=1611184250&vid=16847223521411 ;;;; variantId5:34322460016771 ;;;; variantId2:34322452512899 ;;;; variantId3:34322453889155 ;;;; variantImage1:https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1664797425_medium.jpg?v=1611184240&vid=16847221883011 ;;;; variantId1:34322448646275 ;;;;",
45 "weight": "",
46 "klevu_category": "KLEVU_PRODUCT;Products;;All;;Women Sweatshirts @ku@kuCategory@ku@",
47 "totalVariants": 0,
48 "groupPrices": "",
49 "url": "https://klevu-personalisation-demo.myshopify.com/products/singleroad-mens-hoodies-men-women-2021-spring-sweatshirt-male-japanese-streetwear-oversized-yellow-anime-hoodie-men-sweatshirts",
50 "size": "Asian-M",
51 "name": "Singleroad Men's Hoodies Men Women 2021 Sweatshirt Male Japanese Streetwear Oversized Anime Hoodie Men Sweatshirts",
52 "shortDesc": "gender:gender:men; closure:closure:none; ;;;; Brand Name: Single Road Origin: CN(Origin) Sleeve Length(cm): Full Gender:",
53 "category": "All;;Women Sweatshirts",
54 "typeOfRecord": "KLEVU_PRODUCT"
55 },
56 {
57 "discount": "",
58 "hideGroupPrices": "",
59 "itemGroupId": "5192749842563",
60 "freeShipping": "",
61 "storeBaseCurrency": "EUR",
62 "price": "50.00",
63 "toPrice": "",
64 "imageUrl": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1665231658_medium.jpg?v=1611183787",
65 "currency": "EUR",
66 "inStock": "yes",
67 "id": "34322423840899",
68 "imageHover": "",
69 "sku": "42882422-xl",
70 "brand": "klevu-personalisation-demo",
71 "basePrice": "50.0",
72 "startPrice": "",
73 "image": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1665231658_medium.jpg?v=1611183787",
74 "deliveryInfo": "",
75 "hideAddToCart": "",
76 "salePrice": "50.0",
77 "swatchesInfo": "",
78 "weight": "",
79 "klevu_category": "KLEVU_PRODUCT;Products;;All;;Women Sweatshirts @ku@kuCategory@ku@",
80 "totalVariants": 0,
81 "groupPrices": "",
82 "url": "https://klevu-personalisation-demo.myshopify.com/products/womens-white-printed-hooded-oversize-knitted-sweatshirt",
83 "name": "WoMen's Printed Hooded Oversize Knitted Sweatshirt",
84 "shortDesc": ";;;; Brand Name: FASHİON ROOM Material: Cotton Origin: CN(Origin)",
85 "category": "All;;Women Sweatshirts",
86 "typeOfRecord": "KLEVU_PRODUCT"
87 }
88 ],
89 "filters": []
90 }
91 ]
92}
1<iframe src="https://codesandbox.io/embed/klevu-api-sendbox-4ktfrp?fontsize=14&hidenavigation=0&theme=dark&view=preview&initialpath=?payload=recentlyViewed"
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?