I implemented contact creation and I can’t test it on localhost. It’s giving me a CORS error.
I’ve tried several approaches and nothing works. Here’s what I’ve tried so far:
axios.defaults.headers.common['Authorization'] = `Bearer ${publicRuntimeConfig.ACCESS_TOKEN}`;
axios.defaults.headers.common['Content-Type'] = `application/json`;
axios.defaults.headers.common['Access-Control-Allow-Origin'] = `*`;
axios.defaults.headers.common['Access-Control-Allow-Headers'] = `*`;
axios.defaults.headers.common['Access-Control-Allow-Credentials'] = 'true';
axios.defaults.headers.common['Access-Control-Allow-Methods'] = 'GET,HEAD,OPTIONS,POST,PUT';
axios.post(`https://api.hubapi.com/crm/v3/objects/contacts`, props)
.then((e) => {
console.log('Response');
})
.catch(() => {
console.log('ERROR');
setErrorState();
});
const endpoint = "https://api.hubapi.com/crm/v3/objects/contacts";
const data = await fetch(endpoint, {
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${publicRuntimeConfig.ACCESS_TOKEN}`
},
method: 'POST',
body: JSON.stringify(props)
})
.then(response => {
console.log('response');
})
.catch(error => {
console.log('ERROR');
setErrorState();
});