Page 1 of 1

Sending JSON in the body of an HTTP request

Posted: Fri Aug 08, 2025 5:06 pm
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'
);

Re: Sending JSON in the body of an HTTP request

Posted: Fri Aug 08, 2025 5:46 pm
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.

Re: Sending JSON in the body of an HTTP request

Posted: Fri Aug 08, 2025 6:09 pm
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.

Re: Sending JSON in the body of an HTTP request

Posted: Fri Aug 08, 2025 6:17 pm
by Scott Klement
all you needed to do was change %addr(request) to %addr(request:*data)

no point in going back to the 1990s.

Re: Sending JSON in the body of an HTTP request

Posted: Fri Aug 08, 2025 7:15 pm
by ray.marsh
That was it. Thanks again.