Hello,
I try to send JSON to external API Like that
public void createAndSendJSON()
{
System.Net.WebClient webClient;
System.Text.UTF8Encoding encoder;
try
{
webClient = new System.Net.WebClient();
System.Net.WebHeaderCollection headers = webClient.Headers;
headers.Add("Content-Type", "application/json");
encoder = new System.Text.UTF8Encoding();
str json = FormJsonSerializer::serializeClass(HDCSendSalesQuotationRequest);// use this AX helper class (FormJsonSerializer) to convert to JSON here
info(json);
System.Byte[] encodedBytes = encoder.GetBytes(json);
str APILink = "https://myapi.azurewebsites.net/Approve";
/*System.Byte[] response =*/ webClient.UploadData(APILink, encodedBytes);
//str jsonResponse = webClient.Encoding.GetString(response);
// deserialize result returned from API here using FormJsonSerializer::deserializeClass();
}
catch (Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}
}
contract class code is
[DataContractAttribute]
class HDCSendSalesQuotationRequest
{
str quationId;
boolean approvedOption;
str comment;
CustAccount custAccount;
[DataMemberAttribute]
public str quationId(str _quationId = quationId)
{
quationId = _quationId;
return quationId;
}
[DataMemberAttribute]
public boolean approvedOption(boolean _approvedOption = approvedOption)
{
approvedOption = _approvedOption;
return approvedOption;
}
[DataMemberAttribute]
public str comment(str _comment = comment)
{
comment = _comment;
return comment;
}
}
I constantly get Bad Request error
' The remote server returned an error: (400) Bad Request.'
The format of JSON that is waited by the API is
{
"quationId": "string",
"approvedOption": true,
"comment": "string"
}
json my code sends to API is
{
"approvedOption":false,
"comment":"",
"quationId":"000030"
}
the order is incorrectI but I do not understand how to handle the order of parameters in generated JSON so that it is equal to the one needed.
If you have any ideas please share them with me?