Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Cannot call external API in CRM in Javascript

Posted on by 90

I am trying to call an API from Finance and Operations in CRM Dynamics 365 but i am getting error :

"Access to XMLHttpRequest at 'abc.dynamics.com/api/services/SalesOrderTest' from origin 'xyz.crm.dynamics.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

I tried to set these headers but still getting the error  

   xhr.setRequestHeader("Access-Control-Allow-Origin","*")
   xhr.setRequestHeader("Access-Control-Allow-Credentials""true");
   xhr.setRequestHeader("Access-Control-Allow-Methods""GET, POST, PUT, DELETE, OPTIONS");
   xhr.setRequestHeader("Access-Control-Allow-Headers""*");
 
  • CSafwat Profile Picture
    CSafwat 90 on at
    RE: Cannot call external API in CRM in Javascript

    Hi Bipin,

    This link isn't helpful and i can't find how to enable CORS on F&O.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Cannot call external API in CRM in Javascript

    Hi,

    Check below link which might be helpful.

    community.dynamics.com/.../enable-cors-on-dynamics-365-for-operations

    Please Mark My Answer Verified If I Were Helpful

  • CSafwat Profile Picture
    CSafwat 90 on at
    RE: Cannot call external API in CRM in Javascript

    Thanks Bipin for your reply.

    Could you please tell me how to enable CORS on F&O ?

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Cannot call external API in CRM in Javascript

    Hi,

    You have two options to fix your issue

    1. Enable CORS on target web application which is F&O

    2. Use custom action to execute your api call server side and call custom action from JS n CRM

    Please Mark My Answer Verified If I Were Helpful

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans