Parsing error
After calling an API with
Do request.Get("/api/address/listing")
Set data = {}.%FromJSON(request.HttpResponse.Data)
I get this error:
<THROW>%FromJSON+37^%Library.DynamicAbstractObject.1 *%Exception.General Premature end of data 12 Line 1 Offset 0
any clue what might be causing this?
Product version: Ensemble 2018.1
It looks to me like the data returned in the HTTP response might not be proper JSON. Do you have that data for us to see?
If I do
I get this large output:
v¯fAPI\-e^zCopyFrom+1^%Library.FileBinaryStream.1^1-e^zGetStaffRequest+21^CompBI.bo.APITest.1^1"d^^%Library.FileBinaryStream.1^0,E^zSizeGet+1^%Library.FileBinaryStream.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0"d^^%Library.FileBinaryStream.1^0-E^zCopyFrom+2^%Library.FileBinaryStream.1^1e^^CompBI.bo.APITest.1^0"d^^%Library.FileBinaryStream.1^0-E^zCopyFrom+2^%Library.FileBinaryStream.1^1e^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0d^^CompBI.bo.APITest.1^0E^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^CompBI.bo.APITest.1^0'd^^%Library.DynamicAbstractObject.1^03E^%FromJSON+37^%Library.DynamicAbstractObject.1^1e^^
CompBI.bo.APITest.1^0d^^^
This is definitely not a JSON.
This is not a json message and not even a csv. It is somewhere in the middle. It seems there is some logic mismatch. Ping me a message or linkedin. Can solve it for you and we can post the solution here once done.
https://community.intersystems.com/post/certified-intersystems-professional-available-contract
there's a mistake
Methode CopyFrom(source As %AbstractStream) as %Status
just returns an obviously strange status.
to see the content use DO stream.OutputToDevice()
Obviously, the response.Data does not contain valid JSON. You can simply check the received data by putting the data aside in a temporary global, something like this:
do request.HttpResponse.Data.Rewind() set ^temp.debug($j,"size")=request.HttpResponse.Data.Size set ^("data")=request.HttpResponse.Data.Read(request.HttpResponse.Data.Size) // or just the first 1000 bytes zw ^temp.debug
Now you can take a look on the incoming data, maybe there is an encoding problem or the data do not adhere to JSON specification
Strangely, I recreated that same logic in Powershell using Invoke-Webrequest, and it printed out the json list I'm looking for just fine when I called the API, with a 200 code of success. When I print out the status code in the terminal for the objectscript code, it returns 302, which is a URL redirect, yet they both look as if they have the same functionality.
Add:
set request.FollowRedirect = $$$YES
before sending a GET request.
It returned this:
^temp.debug(6492,"size")=""
^temp.debug(9788,"data")=""
^temp.debug(9788,"size")=0