Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!