Recently Viewed
2 min
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.
Recently Viewed Product Recommendations
The end-point is used for retrieving recently viewed product recommendations.
POST
https://eucs19v2.ksearchnet.com/cs/v2/search
Body Parameters
- typeOfRequestStringrequiredDescription
- customANDQueryStringrequiredDescription
- topIdsArrayDescription
Request Body (JSON)
{
"recordQueries": [
{
"id": "recsRecentlyViewed",
"typeOfRequest": "SEARCH",
"settings": {
"customANDQuery":"(id:\"34322453430403\" OR id:\"34322423840899\")",
"topIds": [
{
"key": "id",
"value": "34322453430403"
},
{
"key": "id",
"value": "34322423840899"
}
],
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-158755634955912036"
]
}
}php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://eucs19v2.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": "recsRecentlyViewed",
"typeOfRequest": "SEARCH",
"settings": {
"customANDQuery":"(id:\\"34322453430403\\" OR id:\\"34322423840899\\")",
"topIds": [
{
"key": "id",
"value": "34322453430403"
},
{
"key": "id",
"value": "34322423840899"
}
],
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-158755634955912036"
]
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;javascript
// WARNING: For POST requests, body is set to null by browsers.
var data = JSON.stringify({
"recordQueries": [
{
"id": "recsRecentlyViewed",
"typeOfRequest": "SEARCH",
"settings": {
"customANDQuery": "(id:\"34322453430403\" OR id:\"34322423840899\")",
"topIds": [
{
"key": "id",
"value": "34322453430403"
},
{
"key": "id",
"value": "34322423840899"
}
],
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-158755634955912036"
]
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://eucs19v2.ksearchnet.com/cs/v2/search");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"recordQueries\": [\r\n {\r\n \"id\": \"recsRecentlyViewed\",\r\n \"typeOfRequest\": \"SEARCH\",\r\n \"settings\": {\r\n \"customANDQuery\":\"(id:\\\"34322453430403\\\" OR id:\\\"34322423840899\\\")\",\r\n \"topIds\": [\r\n {\r\n \"key\": \"id\",\r\n \"value\": \"34322453430403\"\r\n },\r\n {\r\n \"key\": \"id\",\r\n \"value\": \"34322423840899\"\r\n }\r\n ],\r\n \"typeOfRecords\": [\r\n \"KLEVU_PRODUCT\"\r\n ]\r\n }\r\n }\r\n ],\r\n \"context\": {\r\n \"apiKeys\": [\r\n \"klevu-158755634955912036\"\r\n ]\r\n }\r\n}");
Request request = new Request.Builder()
.url("https://eucs19v2.ksearchnet.com/cs/v2/search")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();nodejs
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://eucs19v2.ksearchnet.com/cs/v2/search',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"recordQueries": [
{
"id": "recsRecentlyViewed",
"typeOfRequest": "SEARCH",
"settings": {
"customANDQuery": "(id:\"34322453430403\" OR id:\"34322423840899\")",
"topIds": [
{
"key": "id",
"value": "34322453430403"
},
{
"key": "id",
"value": "34322423840899"
}
],
"typeOfRecords": [
"KLEVU_PRODUCT"
]
}
}
],
"context": {
"apiKeys": [
"klevu-158755634955912036"
]
}
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
200
{
"meta": {
"qTime": 5,
"responseCode": 200
},
"queryResults": [
{
"id": "recsRecentlyViewed",
"meta": {
"qTime": 3,
"noOfResults": 12,
"totalResultsFound": 2,
"typeOfSearch": "WILDCARD_AND",
"offset": 0,
"debuggingInformation": {},
"notificationCode": 1,
"searchedTerm": "*",
"apiKey": "klevu-158755634955912036",
"isPersonalised": false
},
"records": [
{
"color": "White Hoodie thick",
"discount": "",
"hideGroupPrices": "",
"itemGroupId": "5192753152131",
"freeShipping": "",
"storeBaseCurrency": "EUR",
"price": "56.68",
"toPrice": "",
"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",
"currency": "EUR",
"inStock": "yes",
"id": "34322453430403",
"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",
"sku": "30504298-white-hoodie-thick-asian-m",
"brand": "klevu-personalisation-demo",
"basePrice": "56.68",
"startPrice": "48.48",
"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",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "56.68",
"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 ;;;;",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;All;;Women Sweatshirts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"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",
"size": "Asian-M",
"name": "Singleroad Men's Hoodies Men Women 2021 Sweatshirt Male Japanese Streetwear Oversized Anime Hoodie Men Sweatshirts",
"shortDesc": "gender:gender:men; closure:closure:none; ;;;; Brand Name: Single Road Origin: CN(Origin) Sleeve Length(cm): Full Gender:",
"category": "All;;Women Sweatshirts",
"typeOfRecord": "KLEVU_PRODUCT"
},
{
"discount": "",
"hideGroupPrices": "",
"itemGroupId": "5192749842563",
"freeShipping": "",
"storeBaseCurrency": "EUR",
"price": "50.00",
"toPrice": "",
"imageUrl": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1665231658_medium.jpg?v=1611183787",
"currency": "EUR",
"inStock": "yes",
"id": "34322423840899",
"imageHover": "",
"sku": "42882422-xl",
"brand": "klevu-personalisation-demo",
"basePrice": "50.0",
"startPrice": "",
"image": "https://cdn.shopify.com/s/files/1/0386/6653/5043/products/product-image-1665231658_medium.jpg?v=1611183787",
"deliveryInfo": "",
"hideAddToCart": "",
"salePrice": "50.0",
"swatchesInfo": "",
"weight": "",
"klevu_category": "KLEVU_PRODUCT;Products;;All;;Women Sweatshirts @ku@kuCategory@ku@",
"totalVariants": 0,
"groupPrices": "",
"url": "https://klevu-personalisation-demo.myshopify.com/products/womens-white-printed-hooded-oversize-knitted-sweatshirt",
"name": "WoMen's Printed Hooded Oversize Knitted Sweatshirt",
"shortDesc": ";;;; Brand Name: FASHİON ROOM Material: Cotton Origin: CN(Origin)",
"category": "All;;Women Sweatshirts",
"typeOfRecord": "KLEVU_PRODUCT"
}
],
"filters": []
}
]
}Try it here!