#XPRIM_JsonWriter - SetOutputToHttpRequest

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Speedlime
Posts: 6
Joined: Wed Feb 03, 2021 2:52 am

#XPRIM_JsonWriter - SetOutputToHttpRequest

Post by Speedlime » 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

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
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

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
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.

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

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

davidbalansa
Posts: 62
Joined: Mon Feb 01, 2016 10:08 am
Location: Australia

Re: #XPRIM_JsonWriter - SetOutputToHttpRequest

Post by davidbalansa » Tue Jan 11, 2022 6:58 am

You can get the request information if you turn on logging. The following post explains how:

viewtopic.php?f=3&t=2499

Direct link to the LANSA documentation:

https://docs.lansa.com/14/en/lansa018/i ... 1_0395.htm

Hope it helps.

Speedlime
Posts: 6
Joined: Wed Feb 03, 2021 2:52 am

Re: #XPRIM_JsonWriter - SetOutputToHttpRequest

Post by Speedlime » Wed Jan 19, 2022 8:56 pm

Thanks for this, I will set up the logging and see what I get.

Post Reply