#XPRIM_JsonWriter - SetOutputToHttpRequest
Posted: Tue Jan 11, 2022 3:47 am
Afternoon
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
Is there a way I can get to the Json that is been written to the request. ?? either a string or written to a file ?? To check the format and data is correct
I can duplicate the above code and do the following
In debug I can see the string and I can copy to check the format. Seems over kill.
I can read the response like this, and get the required values I need.
Basically I want to get all the Json in the request and the response either in a string or a file, is there a better way other than using the Json Writer to read and write it to a unicodestring variable.
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
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