No JSON Returned if its not HTTP/1.1 200 OK

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
PragueBear
Posts: 5
Joined: Mon Mar 04, 2024 6:02 pm

No JSON Returned if its not HTTP/1.1 200 OK

Post 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 !
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

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

Post 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?
PragueBear
Posts: 5
Joined: Mon Mar 04, 2024 6:02 pm

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

Post 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
PragueBear
Posts: 5
Joined: Mon Mar 04, 2024 6:02 pm

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

Post 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 :(
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

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

Post by Scott Klement »

Yes, use http_req() if you need to get back the response variable when you get a code like 406.
PragueBear
Posts: 5
Joined: Mon Mar 04, 2024 6:02 pm

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

Post 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
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

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

Post 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?
PragueBear
Posts: 5
Joined: Mon Mar 04, 2024 6:02 pm

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

Post by PragueBear »

Hi Scott
Now using http_req() as advised. Looking good
Thank you for your help
Post Reply