I'm trying to make the Http POST on the business central with below Code.
procedure pushworkorder(): text
var
TypeHelper: Codeunit /Type Helper/;
JSONManagement: Codeunit /JSON Management/;
ContentHeaders: HttpHeaders;
Client: HttpClient;
//RequestContent: HttpContent;
Content: HttpContent;
ResponseMessage: HttpResponseMessage;
RequestMessage: HttpRequestMessage;
ToContactNo: Text[30];
Messagetxt: Text[100];
URL: Text[200];
AccessToken: Text;
JsonText: Text;
RequestContentTxt: JsonObject;
JsonData: Text;
Text001: Label 'Message Sent Successfully';
Text002: Label 'Error: ';
begin
URL := '{URL}';
AccessToken := '{AccessToken}';
RequestContentTxt.Add('cr63a_jobnocbs', 'YR-J-23-00004');
RequestContentTxt.Add('cr63a_jobdescriptionscbs', 'Job Description Code CBS Through API');
RequestContentTxt.Add('cr63a_jobtasklinenocbs', '20001');
RequestContentTxt.Add('cr63a_jobtasknocbs', '1010');
RequestContentTxt.Add('msdyn_serviceaccount@odata.bind', '/accounts(028b307b-c526-ee11-9965-6045bd6972c7)');
RequestContentTxt.Add('msdyn_systemstatus', 690970000);
RequestContentTxt.Add('msdyn_workordertype@odata.bind', '/msdyn_workordertypes(e8266b7a-fafa-ed11-8f6e-6045bd6972c7)');
RequestContentTxt.Add('msdyn_workordersummary', 'Work Order Summary Code CBS Through API');
RequestContentTxt.WriteTo(JsonData);
Content.GetHeaders(ContentHeaders);
ContentHeaders.Clear();
ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json');
ContentHeaders.Add('OData-Version', '4.0');
ContentHeaders.Add('OData-MaxVersion', '4.0');
Client.DefaultRequestHeaders.Add('Accept', 'application/json');
Client.DefaultRequestHeaders.Add('Authorization', StrSubstNo('Bearer %1', AccessToken));
Content.WriteFrom(JsonData);
RequestMessage.Content := Content;
RequestMessage.SetRequestUri(URL);
RequestMessage.Method := 'POST';
Client.Send(RequestMessage, ResponseMessage);
ResponseMessage.Content.ReadAs(JsonText);
if not ResponseMessage.IsSuccessStatusCode() then
Error('Failed to Post. Reason => ' + ResponseMessage.ReasonPhrase);
exit(JsonText);
end;
While Debugging, I'm getting the below Response only.
ReasonPhrase:Unsupported Media Type
IsSuccessStatusCode:False
IsBlockedByEnvironment:False
x-ms-service-request-id:e17c9f77-b28d-4035-9aa1-f242ba535eb3;98e76771-00a4-4149-8bdc-86cea1d7469d
Set-Cookie:ARRAffinity=19bdbafc0d65e4ef3f5bdb22f7ea91b0e2a767db4bd5f7070b65ac96605751f65ab954b42cfa12ad9f33ddc80a07e15dd633bd57139a65479392e46e5242529408DB8E928EE03FA81098300741; domain=yallafssb01.crm15.dynamics.com; path=/; secure; HttpOnly
Strict-Transport-Security:max-age=31536000; includeSubDomains
REQ_ID:98e76771-00a4-4149-8bdc-86cea1d7469d
AuthActivityId:e40523c2-5f1e-4c1f-a8bd-bf59f5a8c07c
x-ms-ratelimit-time-remaining-xrm-requests:1,200.00
x-ms-ratelimit-burst-remaining-xrm-requests:7999
X-Source:2292336419021485198160103137477915945255111161997321815722724613513188299215664161159;1651112724517753191487153766223873140752202533417150161172341772511014021069103101
Public:OPTIONS,GET,HEAD,POST
Date:Thu, 27 Jul 2023 10:43:51 GMT
Please Anyone Help me to solve this issue. You help is highly Appreciated.