escape special characters while calling baas from Apigee

Hi,

I have an API that calls baas.

I am getting input for this call from client app and constructing a query string using javascript.

While calling baas I am passing ql statement like below -

ql=select * where name='A & B' order by displayorder ASC

baas is giving error since the query string or URL is not encoded.

I tried using encodeURIComponent() in javascript to encode the query string but still it is not working.

What is the best way to encode this in Apigee so that baas can respond properly?

Thanks,

Santosh

Solved Solved
1 3 1,824
1 ACCEPTED SOLUTION

Hi,

I was getting error when I was creating a querystring using javascript where query parameter values had special characters like '&'. I was later using this query in service callout(this does not matter though). Apigee was truncating the querystring post '&' character in the value of the query parameter.

I later resolved it by using the code like below -

queryString=queryString+" "+encodeURIComponent(string_with_special_characters);

Instead of encoding entire query string I only encoded the part that had special characters and the actual encoding of the '&'s in the query string was taken care by Apigee before sending call to backend.

Thanks,

Santosh

View solution in original post

3 REPLIES 3

Not applicable

Hi Santosh,

The Apigee Edge automatically encodes before sending HTTP requests to BaaS / any other backend.

Please can you try sending the request as it is and let Apigee encode ?

Hi Santosh,

Please let me know if you are using service callout to make BaaS call. When I created the query in javascript using the below code

var baasquery="select * where name='A' order by displayorder ASC"; context.setVariable("baasquery",baasquery);

then used service callout to call BaaS as below

<URL>https://api.usergrid.com/gargitalukdar/HELLO/mycolls?ql={baasquery}</URL>,

I am able to get response from BaaS. Kindly elaborate on how you are trying to set the query and call baas.I am not getting the mentioned error.

Hi,

I was getting error when I was creating a querystring using javascript where query parameter values had special characters like '&'. I was later using this query in service callout(this does not matter though). Apigee was truncating the querystring post '&' character in the value of the query parameter.

I later resolved it by using the code like below -

queryString=queryString+" "+encodeURIComponent(string_with_special_characters);

Instead of encoding entire query string I only encoded the part that had special characters and the actual encoding of the '&'s in the query string was taken care by Apigee before sending call to backend.

Thanks,

Santosh