HTTP 400 Bad Request

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
davidlynch
Posts: 8
Joined: Thu Apr 06, 2023 1:44 am

HTTP 400 Bad Request

Post by davidlynch »

Good Afternoon.

I'm trying to call an API that uses a query parameter that must be enclosed in single quotes - something I've never needed to do previously...

Code: Select all

URL = https://www4.wastedge.com/api/rest/customer/customer?query=update_timestamp>='2024-04-10T00:00:00';
rc = http_req('GET' : URL : *omit : response );
I'm getting a 400 error (Invalid character found in the request target).

I'm sure there is a way around this and can see that the UTF-8 character is %27 but not sure how to use it correctly.

I have tried adding this prior to the http_req, then using %27 but can't seem to get around the 400 issue or find any examples of how to do this properly.

Code: Select all

http_setCCSIDs(1208: 0);
URL = https://www4.wastedge.com/api/rest/customer/customer?query=update_timestamp>=%272024-04-10T00:00:00%27;
rc = http_req('GET' : URL : *omit : response );
Any pointers will be greatly appreciated.

btw using HTTPAPI 1.48

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

Re: HTTP 400 Bad Request

Post by Scott Klement »

What you've posted isn't what you're actually doing because it's not valid RPG syntax. It also isn't valid URL syntax (you can't put the = character in the middle of a field value since it separates the variable name from it's value)

My guess is that you're trying to do this??

Code: Select all

 URL = 'https://www4.wastedge.com/api/rest/customer/customer'
     + '?query=' 
     + http_urlEncode('update_timestamp>=''2024-04-10T00:00:00''');
davidlynch
Posts: 8
Joined: Thu Apr 06, 2023 1:44 am

Re: HTTP 400 Bad Request

Post by davidlynch »

Thanks for your help Scott, that worked.
Post Reply