Community Discussion
Recommendations API blocked by CORS
Hello,
I am tring to implement the recommendations API request on my application (<https://developers.taboola.com/recommendations-api/reference/welcome>).
The problem is when i use fetch browser API it will be blocked by CORS policy.
Following an example that works with Postman but not on Chrome.
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
"placements": [
{
"name": "Placement-1-1",
"recCount": 1,
"organicType": "mix",
"thumbnail": {
"width": 300,
"height": 200
}
}
],
"user": {
"session": "init",
"device": "5bfebde9-c03c-47cd-8f04-2dbe1179b44d",
"languages": [
"IT"
]
},
"app": {
"type": "DESKTOP",
"apiKey": "xxxxxxxxxxxxxxxx",
"name": "test",
"origin": "CLIENT"
},
"view": {
"id": "e8a42862-7437-4b36-826a-9aeb6d8ce5a3"
},
"source": {
"type": "HOME",
"id": "/test_sw.html",
"url": "http\://localhost:8004/test_sw.html"
}
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("<https://api.taboola.com/2.0/json/xxxxxxxxxxxx/recommendations.get">, requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
Is there a way to bypass the CORS check?
Thanks.
Posted by null 4 months ago
Access-Control-Allow-Origin
I'm getting an error sometimes when accessing the item_breakdown endpoint. It'll work fine the first few times and then I'll get his error. I'm masking out specific information in the calls and responses to paste them here.
The endpoint:
Request URL: https://backstage.taboola.com/backstage/api/1.0/##########-altium-sc1/reports/top-campaign-content/dimensions/item_breakdown?start_date=1900-01-01&end_date=2020-02-17&campaign=##########
Referrer Policy: no-referrer-when-downgrade
The response message after the call errors out is:
accept-ranges: bytes
content-length: 0
date: Mon, 17 Feb 2020 21:27:02 GMT
server: nginx
status: 429
via: 1.1 varnish
x-cache: MISS
x-cache-hits: 0
x-served-by: cache-chi21133-CHI
x-timer: S1581974823.691708,VS0,VE160
The error in the browser console is:
Access to XMLHttpRequest at 'https://backstage.taboola.com/backstage/api/1.0/###########-altium-sc1/reports/top-campaign-content/dimensions/item_breakdown?start_date=1900-01-01&end_date=2020-02-17&campaign=###########' from origin 'https://###############.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Posted by Brendan Malone over 4 years ago