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

Notifications

Announcements

No record found.

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,284 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,710 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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans