0

I am trying to make a POST request to an API of mine. As I can see in the API's logs, the requests are received and return a 202 status. However, the Typescript in the Office Scripts show a failure which is not really helpful.

Has somebody experienced the same and has solved it?

async function main(workbook: ExcelScript.Workbook): Promise <void> {

  console.log(new Date().toLocaleString())

  const url: string = 'https://<MYLOGICAPP>.azurewebsites.net:443/api/<WORKFLOWNAME>/triggers/manual/invoke?api-version=2022-05-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<SIG>'

  let res: object
  try{
    const param = {
      method: "POST",
      body: JSON.stringify({ id: 1, success: true })
    };
    console.log(1)
    res = await fetch(url, param);
    console.log(2)
  }
  catch(e){
    console.log(3)
    console.log(res)
    console.log(e)
  }

  console.log(4)
}

As you can see the fetch immediately fails. Here's the output, Guids redacted.

enter image description here

baouss
  • 1,312
  • 1
  • 22
  • 52
  • 1
    It's possible the 202 you're seeing in your API logs is from a CORS check, not the actual API request. Have you configured the allowed origins for your Azure function app? https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#cors – Michelle Ran Feb 08 '23 at 18:04
  • It was indeed a CORS issue. Since the LogicApp does not support changing CORS settings, I deployed an Azure Functions app. Allowing * origin and it works. But now the security center is screaming at me to change that :/ Unfortauntely I cannot just allow a subdomain .officescripts.microsoftusercontent.com. – baouss Feb 16 '23 at 07:34
  • PS: Previously, I was not just a CORS check but the acutal request itself, since I was able to see the request payload (body) in the Logic Apps invocation logs. – baouss Feb 16 '23 at 07:37
  • It's true that allowing any domain can be a security issue. This workaround here might help you: https://stackoverflow.com/questions/69761073/cors-issue-when-calling-api-via-office-scripts-fetch/69803889#69803889 – Michelle Ran Feb 16 '23 at 23:35

0 Answers0