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

Error when calling http request "The remote server returned an error: (400) Bad Request" D365 FO

(0) ShareShare
ReportReport
Posted on by 28

Hi All,

I faced the issue with (400) bad request when tried to hit external api. Here's my snipped code.

Could anybody give some suggestion?

sourceUrl2 = 'https://api-stg/api/payment/update';

authValue = strFmt("Bearer %1", accessObjContract.parmAccessToken());
httpHeader2 = new System.Net.WebHeaderCollection();
httpHeader2.Add("Authorization", authValue);

request2 = System.Net.WebRequest::Create(sourceUrl2);
request2.set_ContentType("application/json");
request2.set_Method("POST");
request2.set_Headers(httpHeader2);

invoiceDataObjContract.parmSourceId("CHG000035EEE");
invoiceDataObjContract.parmProfId("200601782XXX");
invoiceDataObjContract.parmInvoiceId("IV0076");
invoiceDataObjContract.parmInvoiceAmount(200080);
invoiceDataObjContract.parmDudeDate(dateNull());
invoiceDataObjContract.parmTicketId("");
invoiceDataObjContract.parmOutstandingAmount(100000);
invoiceDataObjContract.parmLatestPayDate(dateNull());
invoiceDataObjContract.parmBankInVoucher("xxx");
invoiceDataObjContract.parmTotalPaidAmount(100080);
invoiceDataObjContract.parmInvoiceStatus("Created");
invoiceDataObjContract.parmBankAccNum("xxx");
invoiceDataObjContract.parmBankName("xxx");
invoiceDataObjContract.parmBankAccName("xxx");
invoiceDataObjContract.parmUnitId("xxx");

requestJson = FormJsonSerializer::serializeClass(invoiceDataObjContract);

requestStream = request2.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);
streamWriter.Write(requestJson);

response2 = request2.GetResponse();
responseStream2 = response2.GetResponseStream();
streamReader2 = new System.IO.StreamReader(responseStream2);
responseJson2 = streamReader2.ReadToEnd();

Thanks

Masha

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Are you calling a custom service in D365FO, or some external web service from within D365?

    If it's an external API you need to discuss with the people who developed / maintain that API. We don't know what kind of requests it expects.

  • it.dev Profile Picture
    28 on at

    Hi Nikolaos,

    i need to push the data to this provided json and always got the response 400 bad request.

    [
    
    {
    
    "otcChargeId": "CHG000035EEE",
    
           "proformaId": "200601782XXX",
    
           "invoiceId": "IV0076",
    
           "totalAmountInvoice": "200080",
    
           "dueDate": "2020-12-20",
    
           "ticketId": "",
    
           "outstandingAmount": "100000",
    
           "latestPaymentDate": "2020-12-20",
    
           "bankInVoucher": "xxx",
    
           "totalPayment": "100080",
    
           "invoiceStatus": "Created",
    
           "bankAccountNumber": "xxx",
    
           "bankName": "xxx",
    
           "bankAccountName": "xxx",
    
           "unitId": "xxx"
    
    }
    
    ]

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    So you are calling some external service?

    All I can say that your request is not ok, according to the external service. This you can see in the error message.

    Any other details you need to check with the owner of the service that you are calling. Remember that we don't know anything about that service.

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 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans