Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Call External Api from Javascript

(0) ShareShare
ReportReport
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,545 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,202 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?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans