Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
Integrating API with Wordpress

I've been working on this for months now and have talked with my host, the company etc and I can make my api call work on their developer page which has example code to test their API but for the life of me I cannot get it to work on my Wordpress site and it is very much needed.

My initial code is as follows:

const options = {
  method: 'POST',
  headers: {
    Accept: '*/*',
    'Content-Type': 'application/json',
    Authorization: 'Basic XXXXXXXREDACTEDXXXXX'
  },
  body: JSON.stringify({firstName: 'John', lastName: 'Doe', phoneNumber: '5444455555'})
};

fetch('https://a.eztexting.com/v1/contacts', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

The first error I receive is: Access to fetch at 'https://a.eztexting.com/v1/contacts' from origin 'https://businessofimagination.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

after trying many different headers all over Wordpress and my theme I finally included: "mode: 'no-cors'," into my code

updated code is as follows:

const options = {
  method: 'POST',
  mode: 'no-cors',
  headers: {
    Accept: '*/*',
    'Content-Type': 'application/json',
    Authorization: 'Basic XXXXXXREDACTEDXXXXXX'
  },
  body: JSON.stringify({firstName: 'John', lastName: 'Doe', phoneNumber: '5444455555'})
};

fetch('https://a.eztexting.com/v1/contacts', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Now the errors I receive are: POST https://a.eztexting.com/v1/contacts 403 (403 forbidden) and SyntaxError: Unexpected end of input

I don't understand why it refuses to work, or what in Wordpress is preventing this. Please any help would be incredible. This has been an incredibly frustrating journey for something that in theory should work fairly seamlessly.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda