codeunit 50100 TestWebApi
{
trigger OnRun()
begin
end;
procedure GET_Request(uri: Text) responseText: Text
begin
//json := StrSubstNo('localhost:63273/.../LeaveAccrual');
json := StrSubstNo(uri);
if client.Get(json, Response) then begin
Response.Content.ReadAs(json);
Message(json);
exit(json);
end;
end;
procedure POST_Request(uri: Text; _queryObj: Text) responseText: Text;
var
client: HttpClient;
request: HttpRequestMessage;
response: HttpResponseMessage;
contentHeaders: HttpHeaders;
content: HttpContent;
begin
// Add the payload to the content
content.WriteFrom(_queryObj);
// Retrieve the contentHeaders associated with the content
content.GetHeaders(contentHeaders);
contentHeaders.Clear();
contentHeaders.Add('Content-Type', 'application/json');
// Assigning content to request.Content will actually create a copy of the content and assign it.
// After this line, modifying the content variable or its associated headers will not reflect in
// the content associated with the request message
request.Content := content;
request.SetRequestUri(uri);
request.Method := 'POST';
client.Send(request, response);
// Read the response content as json.
response.Content().ReadAs(responseText);
end;
var
Client: HttpClient;
Response: HttpResponseMessage;
json: Text;
_httpContent: HttpContent;
jsonObj: JsonObject;
}
if it is helpfull to you.
there is Get from Rest api & Post from api.
-------------------------------------------
when you call api from any page
trigger OnOpenPage();
begin
//apiRequestQuery := '{"timestamp": "","LeaveAccrual": "test","InsertedOn": "1753-01-01T00:00:00","InsertedBy": "","UpdatedOn": "1753-01-01T00:00:00","UpdatedBy": "","C_systemId": "c1eef8af-c25e-ea11-b7f0-90b11c65cdee"}';
//webApi.POST_Request('localhost:63273/.../LeaveAccrual', apiRequestQuery);
//webApi.GET_Request('localhost:63273/.../LeaveAccrual');
end;