Page 1 of 1

No JSON Returned if its not HTTP/1.1 200 OK

Posted: Mon Mar 25, 2024 5:26 pm
by PragueBear
Hi
I am calling a web service then using DATA-INTO to receive the JSON to a DS.
When I call and get a "200 OK" message the JSON is returned without issue as the client was successfully updated on the server side.
The client can only be updated once...
When I call again with the same client details .... I get ... a "406 Not Acceptable" message and no JSON is returned!
Is this one for the programmers on the server side ?
Is there a reason the JSON does not get returned when the error occurs on the server side ?

monitor;

response = http_string('POST': url: request: 'application/json');
data-into resultDS %DATA(response:'case=any') %PARSER('YAJLINTO');

on-error;
httpCode = http_error();
apemsg = %trim(httpCode) + ' for ' + %trim(url);
exsr WriteErrorFile;
endmon;

Any input appreciated - I am a newbie to this stuff !

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Mon Mar 25, 2024 6:36 pm
by Scott Klement
I don't understand what you are asking.

Are you telling me that the "406 Not Acceptable" code should also return a JSON and you are not getting it?

Or are you saying that you want to receive a "200 OK" every time?

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Mon Mar 25, 2024 8:19 pm
by PragueBear
When the HTTP Status is 200 ... the JSON response is received and is visible in my program ...
but when HTTP status is not 200 ... i.e 406 - Not Acceptable ... my DATA-INTO/response variable receive no JSON

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Mon Mar 25, 2024 10:14 pm
by PragueBear
I noticed this on another post ...
"http_string() is meant as a way to make it easy to code -- but, it does make some assumptions that may not be right for you. One of its assumptions is that any response code aside from 200=Success means that it should send an *escape message."

Maybe I will have to use http_req() then :(

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Mon Mar 25, 2024 11:59 pm
by Scott Klement
Yes, use http_req() if you need to get back the response variable when you get a code like 406.

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Tue Mar 26, 2024 9:52 am
by PragueBear
Thanks for the that, Scott
I can get the 406 now ... I am more concerned about seeing the returned JSON.
As I said, when it is not 200 OK the JSON does not get returned !
Any help appreciated

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Tue Mar 26, 2024 8:22 pm
by Scott Klement
PragueBear wrote: Tue Mar 26, 2024 9:52 am Thanks for the that, Scott
I can get the 406 now ... I am more concerned about seeing the returned JSON.
As I said, when it is not 200 OK the JSON does not get returned !
Any help appreciated
I'm sorry, I don't understand where you are stuck. You've already discovered from another thread as well as my comments in this thread that you can get the response when you use http_req() instead of http_string(). What part isn't working for you? What is happening in your program?

Re: No JSON Returned if its not HTTP/1.1 200 OK

Posted: Wed Mar 27, 2024 9:31 am
by PragueBear
Hi Scott
Now using http_req() as advised. Looking good
Thank you for your help