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

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

(0) ShareShare
ReportReport
Posted on by 30

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,172 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
    30 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,172 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

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
André Arnaud de Calavon Profile Picture

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

#2
Subra Profile Picture

Subra 385

#3
Martin Dráb Profile Picture

Martin Dráb 252 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans