JSON API
...
Examples
Batch Updates

Custom Attributes

8min

In the Swagger/OpenAPI Specification, you will find that we have some predefined attributes for the item. That will not suffice all the use cases, e.g. you have brand, color, size, etc fields for your product.

Before indexing the additional attributes, the attribute definition needs to be created. Details of various options are available in the API Schema.

PUT
Request
Header Parameters
X-KLEVU-AUTH-ALGO
required
String
This is the algorithm used to create the security bearer token.
X-KLEVU-TIMESTAMP
required
String
This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.
X-KLEVU-APIKEY
required
String
This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.
Content-Type
required
String
This needs to be application/JSON as this request body contains a JSON.
Request Body (JSON)
Responses
200

PUT
Request
Header Parameters
X-KLEVU-AUTH-ALGO
required
String
This is the algorithm used to create the security bearer token.
X-KLEVU-TIMESTAMP
required
String
This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.
X-KLEVU-APIKEY
required
String
This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.
Content-Type
required
String
This needs to be application/JSON as this request body contains a JSON.
Request Body (JSON)
Responses
200


The above API has created two attributes, brand and size. Important to note that the attribute key should be sanitized, without any special characters. This needs to be done only once, not every time you index products. For more information on the supported data types, please refer to the Data Types.

Once the attribute definition is created, let's index the product.

[ { "id": "1", "type": "KLEVU_PRODUCT", "attributes": { "name": { "default": "Product 1" }, "brand" : "UCB", "size" : "s" } }, { "id": "2", "type": "KLEVU_PRODUCT", "attributes": { "name": { "default": "Product 2" }, "brand" : "UCB", "size" : "m" } } ]

In the above example, we have indexed the two new attributes to the product, i.e. brand and size.

Example for MULTIVALUE attribute registration

PUT
Request
Header Parameters
X-KLEVU-AUTH-ALGO
required
String
This is the algorithm used to create the security bearer token.
X-KLEVU-TIMESTAMP
required
String
This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.
X-KLEVU-APIKEY
required
String
This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.
Content-Type
required
String
This needs to be application/JSON as this request body contains a JSON.
Authorization
required
String
This is the generated security token that authenticates the request.
Curl
Responses
200


A sample batch request

[ { "id": "1", "type": "KLEVU_PRODUCT", "attributes": { "name": { "default": "Product 1" }, "brand": "UCB", "materials": [ "20% cotton", "80% polyester" ] } } ]

Abbreviate

The abbreviations feature allows you to automatically generate shortened forms of values for searchable attributes. This can be useful for improving search relevance and efficiency.

By default, the attributes with key "brand" and "manufacturer are abbreviated to enhance search and retrieval efficiency.



The abbreviation logic follows these steps:

  1. Initials Generation: Each word in the submitted data is abbreviated to its initials.
    • Example: "Larsen & Toubro" becomes "L&T".
  2. Handling Special Characters: Special characters like "&" are replaced with no space.
    • Example: "Larsen & Toubro" becomes "LT".

For a given value "Larsen & Toubro", the abbreviations generated are:

  • L&T
    : Using initials with special characters preserved.
  • LT
    : After replacing special characters.

Example

PUT
Request
Header Parameters
X-KLEVU-AUTH-ALGO
required
String
This is the algorithm used to create the security bearer token.
X-KLEVU-TIMESTAMP
required
String
This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.
X-KLEVU-APIKEY
required
String
This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.
Content-Type
required
String
This needs to be application/JSON as this request body contains a JSON.
Request Body (JSON)
Responses
200


Rangeable

This property enhances search flexibility by allowing users to filter data based on numeric ranges, optimizing search and retrieval operations. It only works with the attributes that are registered as NUMBER or MULTIVALUE_NUMBER as a data type.

Example

PUT
Request
Header Parameters
X-KLEVU-AUTH-ALGO
required
String
This is the algorithm used to create the security bearer token.
X-KLEVU-TIMESTAMP
required
String
This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.
X-KLEVU-APIKEY
required
String
This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.
Content-Type
required
String
This needs to be application/JSON as this request body contains a JSON.
Request Body (JSON)
Responses
200