1

I'm getting a Line 15: Failed to fetch error without further details.

This is my script in Excel Web.

async function main(workbook: ExcelScript.Workbook) {
    let sheet = workbook.getActiveWorksheet();
    const company:string  = String(sheet.getRange("C4").getValue());
  const id: string = String(sheet.getRange("C5").getValue());

  sheet.getRange('D4').setValue(await getairequest(company, id));
  sheet.getRange('D5').setValue(Date());

}

async function getairequest(company: string, id: string): Promise <string>{
  const link = encodeURI('{CUSTOM LINK}/' + company + '/' + id);

  console.log(link);
  const response = await fetch(link);
  

  const { data }: { data: JSONData } = await response.json();


  //const json: JSONData = await response.json();
  console.log(JSON.stringify(data));

  return data.text;

}


interface JSONData {
  text: string;
  index: number;
  logprobs: string;
  finish_reason: string;
}

The response of the link is the following:

{"text":"individual text result","index":0,"logprobs":null,"finish_reason":"stop"},

Script will be executed directly in Excel Online (Not via Power Automate), I'm able to modify the response of the Custom Link, due to the fact that this is an internal tool.

Fetch the JSON and put the answer into a cell in Excel.

1
  • Looks like a CORS issue. Does the link that is used in fetch support cross-origin requests? Commented Nov 14, 2022 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.