web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Send records in json format to webapi in d365fo

(0) ShareShare
ReportReport
Posted on by 199

Hi all,

I'm trying to achieve this by using x++ code. I've a situation where i've to pass the id in json format for which i get some response like "successfully updated". I've set the headers with authorization bearer "token number" i.e been generated via username and password.

Now i'm using below code to acheive my task..

RetailWebRequest request;
RetailWebResponse response;
str getData,
rawResponse,
value;

Map data;
System.Net.HttpWebRequest webReq;
System.Net.HttpWebResponse webRes;

System.IO.Stream stream;
CLRObject clrObj;
System.IO.StreamReader streamRead;
System.IO.StreamWriter streamWrite;
System.Net.ServicePoint servicePt;

System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();

//headers.Add("Authorization", 'Bearer ' + _value);

response = webApi.makePostRequest("Url","[\{\"Id\":\"13\"}\]",strFmt("%1",'Bearer ' + _value),"application/json");

rawResponse = response.parmData();

data = RetailCommonWebAPI::getMapFromJsonString(rawResponse);

value = data.lookup("");

On response it throws me an error of unhanded exception. Any idea how to set the body and header on makepostRequest method. Any suggestion would be helpful.

Regards,
Zohan

pastedimage1588276146583v1.png

pastedimage1588276270845v2.png

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    WI would not use that class at all, you can do it with HttpWebRequest directly https://stackoverflow.com/questions/9145667/how-to-post-json-to-a-server-using-c

  • Zohan_93 Profile Picture
    199 on at

    Hi ievgen,

    The link that you've shared doesn't set the body content where i can pass my id, as i've attached some images.

  • Verified answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    If you are using HttpWebRequest  then you have to call GetRequestStream and write the request body to that stream. Take a look at this link

  • Suggested answer
    Obed Miranda Picado Profile Picture
    Microsoft Employee on at

    Hello

    Can you validate with https://stackoverflow.com/questions/4256136/setting-a-webrequests-body-data for the body data needed

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Subra Profile Picture

Subra 386

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 382 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 270 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans