Skip to main content

Notifications

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

How to call a Asynchronous API with Azure URL and subscription key through JavaScript

Posted on by 135

Hello Folks,

I have a query. I’m calling Async Api using a javascript on click of a button. I’m using Azure API URL and subscription key to trigger the same. When i use this from postman using Get method it works but when i try from the JS i don’t get any output nor error. It hit the url but no response. When checked in the splunk logs i get Method as options and not GET and i get 500 error whereas through postman i can update the field in CRM Without any issue. Below is the code. Could anyone suggest a solution please.

function submitStatus(selectedIds) {

    debugger;

    if (selectedIds != null && selectedIds != "") {

        var xRequestID = generateUUID();

        var orderRequest = new XMLHttpRequest();

Xrm.WebApi.retrieveRecord("profile", selectedIds, "?$select=name").then(

                                function success(result) {

 var name=result.name;      

 var url = "https://azureapiurl/“+name ;                                       orderRequest.open("GET", url, true);

 orderRequest.setRequestHeader("api-key", subscriptionKey);

orderRequest.setRequestHeader("Content-Type", "application/json");

 orderRequest.setRequestHeader("X-Request-ID", xRequestID);

 orderRequest.send(null);

  },

 function (error) {}

                );

          }

}

Regards,

Hima 

  • Suggested answer
    sdfasdf Profile Picture
    sdfasdf 840 on at
    RE: How to call a Asynchronous API with Azure URL and subscription key through JavaScript

    Hello,

    What is the error message precisely? It might be the case that you're running into CORS issue, which takes place when a JS code hosted in one domain tries to communicate with a service hosted under a different domain. If that is the case, you might want to consider using JSONP to work around that.

    Hope it helps.

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