Website personalisation: Headless API integration
See: Which integration method is right for me?
Quick start guide
Here is a brief introduction to the steps required for headless API integration with Ometria's website personalisation functionality.
1. Authenticate
Choose your preferred authentication method(s):
- Basic authentication (key and secret)
- IP restriction
For basic authentication use your key and secret to add a header to each request:
const key = "f4198aa7934b402981179610e71dcdbe";
const secret = "AW328UXvlwqfsOkS8smjIGtxfXAqjJxD";
const encoded = btoa(`${key}:${secret}`);
// encoded output ZjQxOThhYTc5MzRiNDAyOTgxMTc5NjEwZTcxZGNkYmU6QVczMjhVWHZsd3Fmc09rUzhzbWpJR3R4ZlhBcWpKeEQ=
POST `https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query`
--header `Authorization: Basic ${encoded}`
2. Make a query
Once your authentication has been configured you'll want to start sending queries to Ometria.
Example request:
POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query"
--header "Authorization: Basic {{ key_secret_encoded }}"
{
"format" : "json",
"elements" : ["category", "cat_1", "cat_2"],
"user": {
"uid" : "ebf3175817b0423eac68a03c68a9be5f",
"sid" : "961c660991a547298af8b31f431a66b0",
"ip_address" : "99.99.99.99"
},
"context": {
"category_id" : "dresses",
"page_url" : "https://mywebsite.com/dresses/",
"user_agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
}
}
The response is always sent in JSON.
Example response:
-{
"request_id": "d6f5fac4c7cd43518342729c5e502ffb",
"response_id": "8f0e2f04dbf44f24be80c60a5cc57625",
"user": +{...},
"header": +{...},
"elements": +{...}
}
See: Headless Query API examples
3. Tracking
To complete the integration, you'll need to use our Tracking APIs to track certain events.
Here's an example of tracking an "add to basket" event:
POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/track"
{
"scope" : "basket",
"action" : "add",
"data" : { "product_id": "{{ product_id }}", "quantity": 1 },
"user": {
"uid" : "ebf3175817b0423eac68a03c68a9be5f",
"sid" : "961c660991a547298af8b31f431a66b0"
}
}
Updated about 1 month ago