Hello,
I consume a webservice REST from a supplier to track the shipments.
In AX I use this code :
static void AccessingAPIv4(Args _args) { str url; str method; str header; System.Net.HttpWebRequest httpRequest; System.Net.HttpWebResponse httpResponse; System.Net.WebHeaderCollection headers; CLRObject clro; int batchSize = 1024; System.IO.Stream receiveStream; System.IO.StreamReader readStream; System.Text.Encoding encode; System.Char[] read; System.Text.StringBuilder sb; System.String readString; str contentEncoding; int countRead; ; url = "https://api.dachser.com/rest/v2/shipmenthistory?tracking-number=3616047827517440"; method = "GET"; try { clro = System.Net.WebRequest::Create(url); httpRequest = clro; headers = new System.Net.WebHeaderCollection(); headers.Add("X-IBM-Client-Id", "77079f46c44fd809905968e00edc7eec"); headers.Add("Accept-Language", "fr"); httpRequest.set_Headers(headers); httpRequest.set_Method(method); httpRequest.set_ContentType("application/json"); httpResponse = httpRequest.GetResponse(); if (httpResponse) { receiveStream = httpResponse.GetResponseStream(); contentEncoding = httpResponse.get_ContentEncoding(); if (contentEncoding) { encode = System.Text.Encoding::GetEncoding(contentEncoding); } else { encode = new System.Text.UTF8Encoding(); } readStream = new System.IO.StreamReader(receiveStream, encode); read = new System.Char[batchSize](); countRead = readStream.Read(read, 0, batchSize); sb = new System.Text.StringBuilder(); while (countRead > 0) { readString = new System.String(read, 0, countRead); sb.Append(readString); countRead = readStream.Read(read, 0, batchSize); } readStream.Close(); info(sb.ToString()); } } catch(Exception::CLRError) { throw error(AifUtil::getClrErrorMessage()); } }
But the result in json is unreadable for a user :
In XML :
I would like to display a clear text. For example :
ID : xxxxxxx
ShipmentDate : 2022-01-25
Forwarder:
PartnerGLN : 4022128000003
Name : DACHSER SE Logistikzentrum Allgäu
AddressInformation:
City: Memmingen
PostalCode : 87700
CountryCode : DE
ShipmentWeight:
Weight : 811.59
Unit : kg
PortOfDeparture: CGC
PortOfDestination : MUC
Consignor:
id:57335219
partnerGLN : 5607427157528
names : Sams c/o Taschenbier
AddressInformation :
Streets : Boulevard de Parc 12
City : Coupvray
postalCode: 77700
CountryCode : FR
.....
....
in XML on the supplier's API I get this information maybe it is clearer for you .
{
"shipments": [
{
"id": "A8653470034371833856",
"shipmentDate": "2022-01-24",
"forwarder": {
"id": "6",
"partnerGLN": "4022128000003",
"names": [
"DACHSER SE Logistikzentrum Allgäu"
],
"addressInformation": {
"city": "Memmingen",
"postalCode": "87700",
"countryCode": "DE"
}
},
"shipmentWeight": {
"weight": 811.59,
"unit": "kg"
},
"portOfDeparture": "CGC",
"portOfDestination": "MUC",
"consignor": {
"id": "84065035",
"partnerGLN": "1774679107268",
"names": [
"Daisy Duck"
],
"addressInformation": {
"streets": [
"Boulevard de Parc 12"
],
"city": "Coupvray",
"postalCode": "77700",
"countryCode": "FR"
}
},
"consignee": {
"id": "57335219",
"partnerGLN": "5607427157528",
"names": [
"Sams c/o Taschenbier"
],
"addressInformation": {
"streets": [
"Bavariafilmpl. 7"
],
"city": "Grünwald",
"postalCode": "82031",
"countryCode": "DE"
}
},
"references": [
{
"code": "003",
"value": "bmHTYBiz6r"
},
{
"code": "007",
"value": "8zW1V6Qulv"
},
{
"code": "HAW",
"value": "nYR45812933"
}
],
"status": [
{
"statusSequence": 1,
"id": "12090048571",
"statusDate": "2022-01-24T04:31:00",
"eventSetter": {
"id": "6",
"partnerGLN": "4022128000003",
"names": [
"DACHSER SE Logistikzentrum Allgäu"
],
"addressInformation": {
"city": "Memmingen",
"postalCode": "87700",
"countryCode": "DE"
}
},
"event": {
"code": "Z",
"extendedCode": "",
"description": "Livré conforme"
},
"signorOfTheProofOfDelivery": "POTTER"
},
{
"statusSequence": 2,
"id": "39703452818",
"statusDate": "2022-01-23T08:19:00",
"eventSetter": {
"id": "250",
"partnerGLN": "4046823000007",
"names": [
"DACHSER Denmark A/S Logistics Centre Copenhagen"
],
"addressInformation": {
"city": "Hvidovre",
"postalCode": "2650",
"countryCode": "DK"
}
},
"event": {
"code": "A",
"extendedCode": "",
"description": "Expédié vers le terminal"
}
},
{
"statusSequence": 3,
"id": "57954173029",
"statusDate": "2022-01-21T19:29:00",
"eventSetter": {
"id": "60",
"partnerGLN": "5990034733003",
"names": [
"LIEGL & DACHSER KFT."
],
"addressInformation": {
"city": "Pilisvörösvár",
"postalCode": "2085",
"countryCode": "HU"
}
},
"event": {
"code": "E",
"extendedCode": "",
"description": "Arrivé au terminal"
}
}
]
}
]
}
How to manage formatting?
Thanks a lot for your help.