OfficeScript - fetch GET request failing

Shadi Rashed 66 Reputation points
2022-05-18T11:11:48.993+00:00

Hello,
I am writing an OfficeScript that for now only has one simple function to send a GET request. For now nothing actually needs to happen with the response. My script is configured like below.
As you can see it is a very simple request, only the Authorization header is different from the examples in the official documentation. The request URL itself also works and is tested with multiple different tools. I cant share the request URL for security reasons.

OfficeScript returns the error: Failed to fetch. Without any further explanation. Interestingly enough, when I add 'mode': 'no-cors' to the configuration parameters then the request works, but the json is not readable. So I think it could have something to do with cors.

Can you please help me understand why the request does not work or how I could see a more insightful error message?

async function main(workbook: ExcelScript.Workbook) : Promise <void>
{
  // Provide the request configuration
  var configurationParams = {
    'method': 'GET',
    'headers': {
      'Authorization': '<some API KEY>'
      }
    };

  const response = await fetch('<some request URL>', configurationParams);
}
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,532 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yutao Huang - MSFT 701 Reputation points Microsoft Employee
    2022-05-20T22:05:07.69+00:00

    This indeed looks like a CORS issue, which could potentially be quite tricky to solve. Please take a look at my answer to a similar question on StackOverflow: https://stackoverflow.com/a/66959919/6656547.

    Basically, if you don't have control over the configuration of the target API service, you may need to build a simple "proxy" service that allows CORS request from your script, then passes along your API requests to the actual service.