GET
POST
PATCH
codeunit 50391 HttpWebRequest
{
trigger OnRun()
begin
end;
procedure APITestConnection(Methode: Code[10]; UserName: Text; Password: Text; Domain: Code[100];
url: text; var ResponseString: Text; var ErrorTxt: Text
)
begin
Clear(Client);
Clear(Request);
Clear(Content);
Clear(Headers);
Client.SetBaseAddress(Url);
Client.UseWindowsAuthentication(UserName, Password, Domain);
Request.Method('GET');
Content.GetHeaders(Headers);
Headers.Remove('Content-Type');
Client.DefaultRequestHeaders.Add('User-Agent', 'Dynamics 365');
Headers.Add('Content-Type', 'application/json;odata.metadata=none');
Client.Timeout(15000);
if Not Client.Send(Request, Response) then
ErrorTxt := ('The call to the web service failed.');
if not Response.IsSuccessStatusCode() then
ErrorTxt := ('Status code: ' + Format(Response.HttpStatusCode()) +
' Description: ' + Response.ReasonPhrase())
else
Response.Content().ReadAs(ResponseString);
If ResponseString <> '' then begin
// JObject.ReadFrom(ResponseString);
// JObject.Get('displayName', JToken);
// ResponseString := 'Test is ok , Company Name : ' + Jtoken.AsValue().AsText();
end;
end;
procedure GETRequest(UserName: Text; Password: Text; Domain: Code[100];
url: text; var ResponseString: Text; var ErrorTxt: Text
)
begin
Clear(Client);
Clear(Request);
Clear(Content);
Clear(Headers);
Client.SetBaseAddress(Url);
Client.UseWindowsAuthentication(UserName, Password, Domain);
Request.Method('GET');
Content.GetHeaders(Headers);
Headers.Remove('Content-Type');
Client.DefaultRequestHeaders.Add('User-Agent', 'Dynamics 365');
Headers.Add('Content-Type', 'application/json;odata.metadata=none');
Client.Timeout(15000);
if Not Client.Send(Request, Response) then
ErrorTxt := ('The call to the web service failed.');
if not Response.IsSuccessStatusCode() then
ErrorTxt := ('Status code: ' + Format(Response.HttpStatusCode()) +
' Description: ' + Response.ReasonPhrase())
else
Response.Content().ReadAs(ResponseString);
PurchHeaderInit(ResponseString);
end;
procedure PatchRequest(UserName: Text; Password: Text; Domain: Code[100];
url: text; var ResponseString: Text; var ErrorTxt: Text
)
begin
Clear(Client);
Clear(Request);
Clear(Content);
Clear(Headers);
Client.SetBaseAddress(Url);
Client.UseWindowsAuthentication(UserName, Password, Domain);
Request.Method('GET');
Content.GetHeaders(Headers);
Headers.Remove('Content-Type');
Client.DefaultRequestHeaders.Add('User-Agent', 'Dynamics 365');
Headers.Add('Content-Type', 'application/json');
Headers.Add('If-Match', '*');
Client.Timeout(15000);
if Not Client.Send(Request, Response) then
ErrorTxt := ('The call to the web service failed.');
if not Response.IsSuccessStatusCode() then
ErrorTxt := ('Status code: ' + Format(Response.HttpStatusCode()) +
' Description: ' + Response.ReasonPhrase())
else
Response.Content().ReadAs(ResponseString);
end;
procedure PurchHeaderInit(JsonText: text)
begin
Clear(TempPurchaseHeader);
if not JObject.ReadFrom(JsonText) then
Error('Invalid response, expected a JSON object');
JObject.Get('value', Jtoken);
if not Jarray.ReadFrom(Format(Jtoken)) then
Error('Array not Reading Properly');
TotalCount := 0;
OrderCount := 0;
TotalCount := Jarray.Count();
for i := 0 to Jarray.Count() - 1 do begin
Jarray.Get(i, Jtoken);
JObject := Jtoken.AsObject();
IF Jtoken.AsObject.Get('No', Jtoken) then begin
TempPurchaseHeader.INIT;
TempPurchaseHeader."Document Type" := TempPurchaseHeader."Document Type"::Order;
TempPurchaseHeader."No." := Jtoken.AsValue().AsCode();
if Jtoken.AsObject.Get('BuyfromVendorNo', Jtoken) then;
TempPurchaseHeader."Buy-from Vendor No." := Jtoken.AsValue().AsCode();
if Jtoken.AsObject.Get('BuyfromVendorName', Jtoken) then;
TempPurchaseHeader."Buy-from Vendor Name" := Jtoken.AsValue().AsText();
if Jtoken.AsObject.Get('OrderDate', Jtoken) then;
TempPurchaseHeader."Order Date" := Jtoken.AsValue().AsDate();
if Jtoken.AsObject.Get('LocationCode', Jtoken) then;
TempPurchaseHeader."Location Code" := Jtoken.AsValue().AsCode();
if Jtoken.AsObject.Get('InterCompanyCode', Jtoken) then;
TempPurchaseHeader."Inter Company Code" := Jtoken.AsValue().AsCode();
TempPurchaseHeader.Status := TempPurchaseHeader.Status::Released;
TempPurchaseHeader.INSERT;
end;
end;
IF NOT TempPurchaseHeader.ISEMPTY THEN BEGIN
IF PAGE.RUNMODAL(0, TempPurchaseHeader) = ACTION::LookupOK THEN BEGIN
Message('Proccess Document No. %1', TempPurchaseHeader."No.");
end;
end;
end;
procedure PurchLineInit(JsonText: text)
begin
end;
procedure SaleshHeaderInit(JsonText: text)
begin
end;
procedure SalesLineInit(JsonText: text)
begin
end;
procedure UpdateSalesHeader()
begin
end;
procedure UpdatePurchHeader()
begin
end;
var
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Headers: HttpHeaders;
Content: HttpContent;
ResponseText: Text;
ErrorBodyContent: Text;
TextContent: Text;
Jtoken: JsonToken;
JObject: JsonObject;
jsonval: JsonValue;
Jarray: JsonArray;
i: Integer;
j: Integer;
TotalCount: Integer;
OrderCount: Integer;
TempPurchaseHeader: Record 38 temporary;
}
No comments:
Post a Comment