Sending JSON in the body of an HTTP request

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
ray.marsh
Posts: 7
Joined: Fri Aug 08, 2025 12:58 pm

Sending JSON in the body of an HTTP request

Post by ray.marsh »

The following code is producing this message: {"statusCode": 400, "body": "Not JSON"}

D HTTPAPI_VERSION...
D C CONST('1.23')
D HTTPAPI_RELDATE...
D C CONST('2008-04-24')

I have verified that the JSON is formatted properly and is present in the request variable at the time of the http call.
The logs on the web-service show there is nothing in the body of the request. Am I using the correct procedure call for this?

request = '{JSON stuff here}' ;

t_Endpoint = 'http://theendpoint.com';

// Notify httpapi of the routine to use to add headers
http_xproc( HTTP_POINT_ADDL_HEADER
: %paddr(addSpecialHeaders)
: %addr(authorizationToken) );

response = 'tmp/TEST.json';

rc = http_url_post( t_Endpoint
: %addr(request)
: %len(%trim(request))
: %Trim(response)
: Timeout
: HTTP_USERAGENT
: 'application/json'
);
Scott Klement
Site Admin
Posts: 906
Joined: Sun Jul 04, 2021 5:12 am

Re: Sending JSON in the body of an HTTP request

Post by Scott Klement »

make sure if this is a VARYING/VARCHAR field that you are getting the address of the *DATA not the address of the length prefix.
ray.marsh
Posts: 7
Joined: Fri Aug 08, 2025 12:58 pm

Re: Sending JSON in the body of an HTTP request

Post by ray.marsh »

That was the issue. Since the body JSON is fairly small I changed the variable definition to char(500) and cleared it before setting the value. Clearing shouldn't make any difference but I did it anyway.

Thank you very much.
Scott Klement
Site Admin
Posts: 906
Joined: Sun Jul 04, 2021 5:12 am

Re: Sending JSON in the body of an HTTP request

Post by Scott Klement »

all you needed to do was change %addr(request) to %addr(request:*data)

no point in going back to the 1990s.
ray.marsh
Posts: 7
Joined: Fri Aug 08, 2025 12:58 pm

Re: Sending JSON in the body of an HTTP request

Post by ray.marsh »

That was it. Thanks again.
Post Reply