I know I am not the only one with this problem and I have already read many articles on the subject in the last two days, especially in this community. Unfortunately, I have not yet found a working answer for my case. Therefore I try to post my code here and hope for help.
I am trying to add a profile to a list using fetch(). The site is ssl secured.
Here is my code:
const api = "123456789123456789";
const list_id = "LIstId";
const url = `https://a.klaviyo.com/api/v2/list/${list_id}/members?api_key=${api}`;
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Access-Control-Allow-Origin", "*");
var raw = JSON.stringify({
"profiles": [
{
"first_name": "Henry",
"last_name": "Dust",
"email": "henry@dust.com"
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(url, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error))
But all i get is:
Access to fetch at 'https://a.klaviyo.com/api/v2/list/ListId/members?api_key=123456789123456789' from origin 'https://liveurl.com' has been blocked by CORS policy
Any help is appreciated, I'm stuck here for 2 days now.
Thank you