Search code examples
javascriptsharepointdynamics-crmazure-ad-graph-api

Call the SharePoint REST API from Dynamics record (form)


My objective is to call the MS Graph API on form load, then once I have the access token, to then call the SharePoint API to query the members of a particular site group. I am stuck on CORS implementation (the call works from Postman). I have added a redirect-uri within my app registration in Azure, but I am still receiving the same error message every time.

Error: Access to fetch at 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token' from origin 'https://xxxxx.crm.dynamics.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

JS Code to Call MS Graph API

Redirect URI in Azure App Registration

Any insight will be helpful! Please let me know if I should add clarity/details.


Solution

  • The issue was CORS policy. I resolved it by using an async JavaScript call to a Power Automate flow. The flow natively is allowed in the policy. Once the flow finishes, it returns a response which the script is waiting for.