Customer Bias using the REST API
To get Customer Bias send a HTTP POST request to the endpoint at https://core.helloretail.com/serve/customer/bias
. The content type must be application/json
or text/plain
1.
The JSON body must contain the following properties
Property | Type | Description |
---|---|---|
websiteUuid |
String | The website uuid to request. |
trackingUserId |
String | Tracking user id identifying the customer that you want bias for. The value must be generated by Hello Retail. You can read more about the tracking user here. Required if email or customerId are not provided |
email |
String | Email address of the customer you want bias for. The call will find data for customers that have been associated with this email address, either through conversion tracking or by using the setCustomerEmail SDK method. Required if trackingUserId or customerId is not provided. Notice that using email to lookup the customer bias requires that you include your API key in the request |
customerId |
String | A customer id determined by the shop. The call will find data for customers that have been associated with this customerId, either through conversion tracking or by using the setCustomerId SDK method. Required if trackingUserId or email are not provided. Notice that using customerId to lookup the customer bias requires that you include your API key in the request |
fields |
String[] | A list of field names that you want to fetch customer bias for. |
numberOfValues |
Number | The number of values you want to fetch for each field. Maxumum value is 10. Optional, default is 5 |
Example request
async function getCustomerBias(email, websiteUuid){
var data = {
websiteUuid: websiteUuid,
email: email,
fields: ['brand', 'extraData.margin'],
numberOfValues: 2
};
var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
}
const response = await fetch('https://core.helloretail.com/serve/customer/bias', options);
return await response.json();
};
Response
The response will contain a success
property indicating if the call succeeded and a bias
property containing the requested data. If you had requested three values for the brand
and extraData.margin
fields it will look someting like this:
{
"bias": {
"extraData.margin": [
{
"weight": 50,
"value": "medium"
},
{
"weight": 40,
"value": "high"
},
{
"weight": 10,
"value": "low"
}
],
"brand": [
{
"weight": 60,
"value": "Adidas"
},
{
"weight": 30,
"value": "Nike"
},
{
"weight": 10,
"value": "Puma"
}
]
},
"success": true
}
-
The reason for supporting text/plain is to allow requests to this endpoint, made from the browser, to be categorized as simple thereby avoiding CORS preflight requests. You can read more here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests ↩