question

ShadiRashed-1057 avatar image
0 Votes"
ShadiRashed-1057 asked YutaoHuang-MSFT answered

OfficeScript - fetch GET request failing

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-scripts-excel-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YutaoHuang-MSFT avatar image
0 Votes"
YutaoHuang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.