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

205
Visualizações
Failed to fetch error when using fetch API in office scripts

I am trying to run a post request from office scripts on an api, but kept getting a failed to fetch error each time when I add : "Content-type": "application/json" to the header, once I remove the content-type option or replace its value with something other than "application/json" , then the fetch request works , but returns an error with code 0 and validation error messages indicating that the userName and password ('which are already defined in the body could not be found'): Below is the code

    async function main(workbook: ExcelScript.Workbook) {

    const param = {
      method: "POST",
      headers: {
        //"Content-type": "application/json"
      },
      body: JSON.stringify({ user_id: "uname", password: "pwd"})
   
    };

  await fetch("https://testAPI/login/", param).then(response => response.json())
    .then(data => console.log(data));
  }

error when I run this code with Content-Type header set to 'application/json' (line 33 contains the fetch instruction ):

Line 33: Failed to fetch

Error when I run this code with content-Type set to 'text/plain', other options or completely removing the content-type property from the header :

enter image description here

Also , this same request from postman or power automate with header content-type set to 'application/json' runs successfully , the issue happens only in office script

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