I am calling a external API, passing in some Json and getting Json back
I am writing the Json directly to the http request see below
Code: Select all
* Add the constructed JSON to the request body
#Writer.SetOutputToHttpRequest HttpRequest(#request)
* Construct the JSON IN
* Root
#Writer.BeginObject
#Writer.WriteString Name('CustomerNumber') Value('WD0009')
#Writer.WriteString Name('ProductGroup') Value('VBRO')
#Writer.WriteString Name('ProductSize') Value('EAAA')
* End Root Object
#Writer.EndObject
I can duplicate the above code and do the following
Code: Select all
* Save as String for debug
#Writer.SetOutputToString String(#MyJsonStringIn)
#Writer.BeginObject
#Writer.WriteString Name('CustomerNumber') Value('WD0009')
#Writer.WriteString Name('ProductGroup') Value('VBRO')
#Writer.WriteString Name('ProductSize') Value('EAAA')
* End Root Object
#Writer.EndObject
I can read the response like this, and get the required values I need.
Code: Select all
* Request OK
If (#request.Response.IsSuccessfulRequest)
* Status OK 200
If (#request.Response.IsSuccessHttpStatusCode)
* Json Response
#Reader.SetSourceHttpResponse HttpResponse(#request.Response)
#M6CURR := #Reader.ReadStringWithName( "Currency" ).AsNativeString
#STD_PRICE := #Reader.ReadStringWithName( "Price" ).AsNumber
Endif
Endif
Reason is for logging what went in and what came back either to a audit record (with string value) or to a file on the PC or IFS.
Regards