Hello,
Here's the solution for ODATA API Call for Authorization and to Get or Post the request :
Procedure GetAuthorizationToken();
begin
Content.GetHeaders(contentHeaders);
RequestMessageforToken.GetHeaders(RequestHeaderforToken);
RequestMessageforToken.SetRequestUri(Rec."Authorization URL");
RequestMessageforToken.Method('POST');
if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json');
RequestMessageforToken.Content(Content);
IsSuccessful := HttpClient.Send(RequestMessageforToken, ResponseMessage);
if not IsSuccessful then
Error('Status Code: %1\ Reason : %2', ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase)
else begin
ResponseMessage.Content.ReadAs(ResponseText);
JObject.ReadFrom(ResponseText);
end;
Procedure PostURL();
begin
Content.GetHeaders(contentHeaders);
RequestMessageforPost.GetHeaders(RequestHeaderforPost);
RequestHeaderforPost.Add('Authorization', 'Bearer ' + Rec."Authorization Token");
RequestMessageforPost.Method('POST');
RequestMessageforPost.SetRequestUri(Rec."Post URL");
if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');
ContentHeaders.Add('Content-Type', 'application/json');
RequestHeaderforPost.Add('Accept', '*/*');
RequestMessageforPost.Content(Content);
IsSuccessful := HttpClient.Send(RequestMessageforPostContainer, ResponseMessage);
if not IsSuccessful then
Error('Status Code: %1\ Reason : %2', ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase)
else begin
ResponseMessage.Content.ReadAs(ResponseText);
JObject.ReadFrom(ResponseText);
end;
Hope this solution helps.
May other expert's give's you better solution's.
Thank You,
Shrey Chauhan