Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Make POST request to secure (https) external API via JS script on Ribbon Workbench

(1) ShareShare
ReportReport
Posted on by 2

Hello,

I am using CRM Online and am having trouble making a request to an external api.  Here is my code

function sendRequest() {
var xmlHttp = new XMLHttpRequest();
var url = "myapi.com/api";
var data = {"title":"Testing Here",""themeId":"123456789876532"};
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
    callback(xmlHttp.responseText);
}
xmlhttp.setRequestHeader("access_token", "myaccesstoken");
xmlHttp.open("POST", url, true); // true for asynchronous
xmlHttp.send(JSON.stringify(data));
}
  • Suggested answer
    cjanow3 Profile Picture
    cjanow3 2 on at
    RE: Make POST request to secure (https) external API via JS script on Ribbon Workbench

    Solution:

    function sendRequest() {
    var data = JSON.stringify(
     
    {
    "title":"Testing Here",
    "themeId":"mythemeid});
    var url = "">https://my.api";
    var xhr = new XMLHttpRequest();
    xhr.withCredentials = false;
    xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4) {

    var response = this.responseText;
    console.log(response);

    // can update fields here with response text
    }
    });
    xhr.open("POST", url);
    xhr.setRequestHeader("access_token", "my-api-key");
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(data);
    }
  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Make POST request to secure (https) external API via JS script on Ribbon Workbench

    Hi,

    To isolate if this is causing becuse of CRM or there is a problem within your script, try to execute your script somewhere else. You can try it on JSfiddle - https://jsfiddle.net/

    Hope this 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

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... 292,492 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans