Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Suggested answer

Call External Api from Javascript

Posted on by

hi Guys, i have one javascript i need to call external webapi with one parameter how to call the webapi using javascript and capture the return value to the javascript in dynamcis crm.

Thank You

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,543 on at
    RE: Call External Api from Javascript

    Hi ,

    Please find the sample code for the POST Request,

    Note: Only HTTPS requests are allowed from D365.

    var data = JSON.stringify({

     "name": "morpheus",

     "job": "leader"

    });

    var url = "https://reqres.in/api/users";

    var xhr = new XMLHttpRequest();

    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {

     if (this.readyState === 4) {

       console.log(this.responseText);

     }

    });

    xhr.open("POST", url);

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

    xhr.send(data);

    You can also learn how to make HTTPS call using JS or Ajax request.

    https://www.freecodecamp.org/news/here-is-the-most-popular-ways-to-make-an-http-request-in-javascript-954ce8c95aaa/

  • cloflyMao Profile Picture
    cloflyMao 25,194 on at
    RE: Call External Api from Javascript

    Hi Dinesh,

    It depend on what kind of the request method the API uses, and whether you need a authentication to call it.

    Here is a simple demo to call NASA(https://api.nasa.gov/#getting-started) public API, it can be easily done with jQuery ajax method.

    (This API is to get an article information, and I only get its title field from callback result)

    1. Add jQuery and your own js libraries in CRM form.

    5270.333.PNG

    2. Add your ajax call function in js by yourself.

    3113.222.png

    3. In my demo, I call the function when form load

    2555.444.png

    result:

    5270.333.PNG

    There are some previous discusses about your question, you could take them as reference: 

    https://community.dynamics.com/crm/f/117/t/270302 

    https://community.dynamics.com/crm/f/117/t/276186 

    Regards,

    Clofly

  • OliverFlint Profile Picture
    OliverFlint 135 on at
    RE: Call External Api from Javascript

    You could use the fetch api (not supported by IE without a polyfil though) developer.mozilla.org/.../Fetch_API

    Or JQuery... api.jquery.com/.../ajax

    Or one of the many other libraries out there.

    What is the external webapi? Does it not provide documentation?

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans