Can anyone please share the script for url encoded content type.
Can anyone please share the script for url encoded content type.
codeunit 50126 MyCodeunit3
{
procedure MakeRequest(uri: Text; payload: Text) responseText: Text;
var
client: HttpClient;
request: HttpRequestMessage;
response: HttpResponseMessage;
contentHeaders: HttpHeaders;
content: HttpContent;
skudetails: record 50138;
tmpString: Text;
// TypeHelper: Codeunit "Type Helper";
granttype: text;
json_Array: JsonArray;
json_Object: JsonObject;
json_Object8: JsonObject;
json_Object1: JsonObject;
json_Object2: JsonObject;
json_Object3: JsonObject;
json_Array18: JsonArray;
json_Token19: JsonToken;
json_Array4: JsonArray;
json_Object5: JsonObject;
json_Value: JsonValue;
json_Token: JsonToken;
PaymentID3: text;
json_Object21: JsonObject;
s: Integer;
json_Token1: JsonToken;
json_Object18: JsonObject;
Coundt: Text;
json_Object19: JsonObject;
ItemNo: Text[50];
json_Array5: JsonArray;
N: Integer;
h: Integer;
json_Token15: JsonToken;
json_Token3: JsonToken;
json_Token4: JsonToken;
json_Token2: JsonToken;
json_Array20: JsonArray;
json_Object6: JsonObject;
json_Token18: JsonToken;
json_Array8: JsonArray;
json_Token20: JsonToken;
json_Object4: JsonObject;
json_Array3: JsonArray;
valueJToken: JsonToken;
json_Token6: JsonToken;
json_Array9: JsonArray;
r: Integer;
Z: Integer;
json_Array7: JsonArray;
json_Array1: JsonArray;
json_Token9: JsonToken;
json_Object7: JsonObject;
json_Object10: JsonObject;
json_Array2: JsonArray;
json_Token7: JsonToken;
InvoiceNo: Text[50];
i: Integer;
j: Integer;
k: integer;
O: Integer;
m: integer;
p: integer;
skudetails1: Record skudetails;
skuList: Text;
begin
// Add the payload to the content
content.WriteFrom(payload);
Json_object.WriteTo(tmpString);
content.WriteFrom(tmpString);
content.ReadAs(tmpString);
// Retrieve the contentHeaders associated with the content
content.GetHeaders(contentHeaders);
contentHeaders.Remove('Content-Type');
contentHeaders.Add('Content-Type', 'application/x-www-form-urlencoded');
contentHeaders.Remove('ApiKey');
client.DefaultRequestHeaders.Add('ApiOwner', 'xxx');
client.DefaultRequestHeaders.Add('ApiKey', 'xxx');
// contentHeaders.Add('accept', 'application/json');
content.GetHeaders(contentHeaders);
// 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);
Message(responseText);
Clear(skuList);
if json_Token.ReadFrom(responseText) then begin
if json_Token.IsObject then begin
json_Object1 := json_Token.AsObject();
if json_Object1.Get('skulist', valueJToken) then begin
if valueJToken.IsArray then begin
json_Array := valueJToken.AsArray();
for i := 0 to json_Array.count - 1 do begin
json_Array.Get(i, json_Token);
if json_Token.IsObject then begin
json_Object := json_Token.AsObject();
//To get skuList_skucode
if json_Object.Get('skuList_skucode', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.Init();
skudetails.skuList_skucode := valueJToken.AsValue().AsText();
end;
end;
end;
//to get skuList_skuName
if json_Object.Get('skuList_skuName', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_skuName := valueJToken.AsValue().AsText();
// skuList := valueJToken.AsValue().AsText();
end;
end;
end;
//--
//To get skuList_classification
if json_Object.Get('skuList_classification', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_classification := valueJToken.AsValue().AsText();
end;
end;
end;
//To get skuList_parentSKU
if json_Object.Get('skuList_parentSKU', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_parentSKU := valueJToken.AsValue().AsText();
end;
end;
end;
//To get skuList_desc
if json_Object.Get('skuList_desc', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_desc := valueJToken.AsValue().AsText();
end;
end;
end;
//To get "skuList_detailDESC
if json_Object.Get('"skuList_detailDESC', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_detailDESC := valueJToken.AsValue().AsText();
end;
end;
end;
//To get skuList_length
if json_Object.Get('skuList_length', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_length := valueJToken.AsValue().AsText();
end;
end;
end;
//To get skuList_width
if json_Object.Get('skuList_width', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_width := valueJToken.AsValue().AsText();
end;
end;
end;
//To get skuList_weight
if json_Object.Get('skuList_weight', valueJToken) then begin
if valueJToken.IsValue then begin
if not valueJToken.AsValue().IsNull then begin
skudetails.skuList_weight := valueJToken.AsValue().AsText();
end;
end;
end;
Hi,
Please share your code.
Thanks.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156