Page 1 of 1

HTTP 400 Bad Request

Posted: Thu Apr 11, 2024 5:42 am
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.

Re: HTTP 400 Bad Request

Posted: Thu Apr 11, 2024 5:49 am
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''');

Re: HTTP 400 Bad Request

Posted: Thu Apr 11, 2024 9:54 pm
by davidlynch
Thanks for your help Scott, that worked.