Skip to main content

Notifications

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

cross domain web api call from CRM using JavaScript

Posted on by 92

i want to validate address for that i have made web api call onsave.

wen i call to cross domain api for validate data at that time i am facing below issue.

Access to fetch at 'api.easypost.com/.../addresses' from origin 'toastmastersdevtrng.crm.dynamics.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

working fine in postman.

my code is below.

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Accept", "application/json");
myHeaders.append("authorization", "Basic ---------------------");
myHeaders.append("crossDomain", "true");
myHeaders.append("Access-Control-Allow-Origin", "">devtrng.crm.dynamics.com/");
myHeaders.append("Access-Control-Allow-Credentials", "true");
myHeaders.append("Access-Control-Allow-Methods", "POST");
myHeaders.append("Access-Control-Allow-Headers", "Overwrite, Destination, Content-Type, Depth, User-Agent, Translate, Range, Content-Range, Timeout, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Location, Lock-Token,DAV, content-length, Allow");
myHeaders.append("Access-Control-Max-Age", "3600");

var raw = JSON.stringify({"street1":"9127 S Jamaica St","street2":"","city":"Englewood","state":"CO","zip":"80112","country":"United States","verify":["delivery"]});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("">api.easypost.com/.../addresses", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Please help to archive this.

Thanks in advance!!

  • Maulik Lakhani Profile Picture
    Maulik Lakhani 92 on at
    RE: cross domain web api call from CRM using JavaScript

    We need to verify api response with user before record going to save so any best option?

  • Maulik Lakhani Profile Picture
    Maulik Lakhani 92 on at
    RE: cross domain web api call from CRM using JavaScript

    doesn`t help..

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: cross domain web api call from CRM using JavaScript

    Hi,

    Check below article which is implemented for CRM 2013. But you can try in your instance to check it if works.

    xrmdynamicscrm.wordpress.com/.../

    Please mark my answer verified if i were helpful

  • Suggested answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: cross domain web api call from CRM using JavaScript

    Hi Maulik,

    D365 actually does not allow calls to cross domain APIs, you have following alternatives.

    1)Plugin/Custom workflow

    2)PCF control

    Thanks,

    Ketan

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans