2

Trying to run the following code in excel office script, but it keep returning the "Maximum call stack size exceeded" error

    async function main(workbook: ExcelScript.Workbook) {
        // Your code here
        const cuslocation = "New York"
        const endpoint = "http://api.weatherstack.com/current?access_key=****367d8059062daa61b5**********&query="+ colocation;
        const response = await fetch(endpoint)
        console.log(response. Text());
    }

Learning office script, so making this easy api call and trying to log data to the excel sheet.

Brian Gonzalez
  • 1,178
  • 1
  • 3
  • 15

1 Answers1

1

This worked for me:

async function main(workbook: ExcelScript.Workbook) {
  const endpoint = "https://jsonplaceholder.typicode.com/todos/1" ;
  const response = await fetch(endpoint)
  let json: unknown = await response.json()
  console.log(JSON.stringify(json));
}

I used my own URL because your API key expired. You should be able to easily substitute your URL into "endpoint".

By the way, in your example above, "New York" needs to be encoded as "New%20York". This is the website that I used to encode strings: https://meyerweb.com/eric/tools/dencoder/.

howard_9
  • 413
  • 3
  • 15