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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

400 bad request error

(0) ShareShare
ReportReport
Posted on by 167

Hi All ,

i m sending  json  'POST' request and its acting very wierd .  I have Order and  15 OrderLineItem 1:N .

I have plugin which fires on update of Order field and covert the json and send to particular url , but problem is sometimes it send all  15 OrderLineItem on retriggering it twice or thrice and some times it send only 5 OrderLineItem .And when i tried to test the issue via console and postman then  return 400 ERROR BAD REQUEST when i tested on Postman tool . However , i can see all data has been serialized in plugin trace log . but only 5 OrderLineItem have been sent to vendor . and rest have been not delivered to vendor .

How can i find out where the problem is , is it at crm side or is it at server side where api is hosted and how can we fix this , and why only partial orderlineitems are getting sent .

I have the same question (0)
  • rthompson Profile Picture
    1,532 on at

    Hi,

    Are you able to show your code?

  • Shahzeb Khan Profile Picture
    167 on at

    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(SalesOrder));

               //write newly created object() into memory stream

               serializer.WriteObject(serializememoryStream, orderentity); // I CAN SEE ALL DATA JSON IN orderentity  , however only few orderlines go through not all .

               serializememoryStream.Position = 0;

               StreamReader sr = new StreamReader(serializememoryStream);  

               string json = sr.ReadToEnd();

               //get JSON data serialized in string format in string variable

               string serializedresult = Encoding.UTF8.GetString(serializememoryStream.ToArray());

               //tracer.Trace("serialised data" + serializedresult);

               byte[] requestData = Encoding.UTF8.GetBytes(serializedresult);

               request.Method = "POST";

               request.ContentType = "application/json";

               request.ContentLength = requestData.Length;

               request.KeepAlive = false;

               request.Credentials = new NetworkCredential(_username, _password);

               ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 |

                                                      SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

               Stream requestStream = request.GetRequestStream();

               requestStream.Write(requestData, 0, requestData.Length);

               try

               {

                   string objText;

                   using (var response = request.GetResponse())    // AT THIS LINE RESPONSE EXCEPTION COMES AS 400 BAD REQUEST WHERE MY PARTIAL DATA IS SENT, ALL DATA DOES NOT GO

                   {

                       var reader = new StreamReader(response.GetResponseStream());

                       objText = reader.ReadToEnd();

                   }

                   //Json String that we get from web api

                   string responseString = objText;

                   //tracer.Trace(" response" + responseString);

                   Result deserialisedresult = new Result();

                   DataContractJsonSerializer resultserializer =

                       new DataContractJsonSerializer(deserialisedresult.GetType());

                   MemoryStream deSerializememoryStream = new MemoryStream(Encoding.UTF8.GetBytes(responseString));

                   //get the Desrialized data in object of type Result

                   deserialisedresult = (Result)resultserializer.ReadObject(deSerializememoryStream);

                   deSerializememoryStream.Close();

                   //updatestatus to inprogress

                   Entity toupdate = new Entity("salesorder") { Id = salesorderentity.Id };

                   //toupdate["asc_netsuiteintegrationstatuscode"] = new OptionSetValue(860000002);

                   //toupdate["asc_netsuiteintegrationdetailstxt"] = "Data update submitted on " + DateTime.Now.ToShortDateString();

                   if (iscreate)

                       toupdate["submitdate"] = DateTime.Now;

                   //service.Update(toupdate);

               }

               catch (Exception e)

               {

                   //updatestatus to error

                   Entity toupdate = new Entity("salesorder") { Id = salesorderentity.Id };

                   toupdate["asc_netsuiteintegrationstatuscode"] = new OptionSetValue(860000004);

                   toupdate["asc_netsuiteintegrationdetailstxt"] = "Error: " + e.Message;

                   //service.Update(toupdate);

               }

           }

  • Shahzeb Khan Profile Picture
    167 on at

    MAIN ISSUE IS IT DOES NOT SEND ALL DATA, WHY IS SEND ONLY PARTIAL DATA AND IF I RETRIGGER IT AGAIN THEN ALL DATA IS SENT WITH SAME PLUGIN , I HAVE TESTED ON POSTMAN ALSO SAME, IS THERE SOMETHING IN MY CODE I NEED TO CHANGE OR IS IT THE ISSUE AT SERVER, IF SERVER ISSUE HOW CAN I FIX IT OR TROUBLESHOOT .

    KINDLY GUIDE .

  • rthompson Profile Picture
    1,532 on at

    Hi Shahzeb,

    I am reviewing your code.

    I am assuming you are online.  If so,  you have to put in a support ticket with Microsoft support.

    admin.powerplatform.microsoft.com/support

    This is the down side for online.

  • rthompson Profile Picture
    1,532 on at

    If you are saying that some data is being sent and doing a trigger again then all data is being sent.

    Not saying this is it.  Please read up on this.  I found this link.

    community.dynamics.com/.../portal-number-of-concurrent-requests-exceeded-the-limit-of-40

  • Shahzeb Khan Profile Picture
    167 on at

    No , this does not related to my problem .

    Can you tell me , is the problem in my code or is it server issue ?

  • meelamri Profile Picture
    13,218 User Group Leader on at

    hello,

    Please did you test your Post request within a c# consolApp ?

    Mehdi,

  • Shahzeb Khan Profile Picture
    167 on at

    Yes, it sends data, on response i get bad request 400 via console .

    Plugin trace shows all json captured however vendor says only few ordelines json recieved not all .

    i dont know, why its acting this way .

  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Please modify the request until success using Postman Client ! Then test in ConsolApp.

  • Shahzeb Khan Profile Picture
    167 on at

    in postman, its 200 ok, using plugin only they are getting partial data, however in plugin trace log, we see entire data sent .

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 189 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
11manish Profile Picture

11manish 76

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans