I can't test api endpoints on localhost

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();
 });

Hey, @MAlmeida4 :waving_hand: Regarding the CORS issue, that is the expected behaviour. You’ll need to look into other solutions:

  • create a backend proxy
  • utilize a service like ngrok
  • use Postman or CURL to make requests directly to the endpoint(s) you are working with

Have fun testing! — Jaycee