API ReferenceAnnouncementsCommunity Discussion
API ReferenceCommunity DiscussionAnnouncementsSubscribeLog In
Community Discussion

Community Discussion

Ask a Question
Back to All

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.