Forum Discussion
I was told to try something like this and it is working.
My rest API requires a query parameter.
http://ServiceURL?query=select * from table where id=1234
I had put in the URL into the Service URL box and then added a query parameter called query.
That did not work.
What does work is this:
‘https://ServiceURL /services/?query=’ + encodeURIComponent(‘select * from incidents where id < 1000’)
And that entire line went into the ServiceURL.
Seems that they do not fix the encoding in the query parameters.
Set the Service URL to “https://ServiceURL/services” and use the “Query parameters” table to set the query parameters. See the docs for this snap.
- Garrett5 years agoNew Contributor II
That is what I tried but it did not work without adding the encodeURIComponent function on the query.
My endpoint said that there were invalid characters when I did it as the document shows.
I tried putting the encodeURIComponent function into the query parameter but it doesn’t evaluate the function it sends it as text to the endpoint instead.
- cjhoward185 years agoEmployee
Do you have the “=“ sign enabled to make it evaluate as an expression and not just plain text?
- Garrett5 years agoNew Contributor II
I get this error:
Could not compile expression: https://serviceurl … (Reason: Encountered extraneous input ‘:’ at line 1:5; expecting={, ‘||’, ‘&&’, ‘^’, ‘==’, ‘!=’, ‘>’, ‘<’, ‘>=’, ‘<=’, ‘+’, ‘-’, ‘*’, ‘/’, ‘%’, ‘?’, ‘instanceof’, ‘in’, ‘matches’, ‘[’, ‘(’, ‘.’, PropertyRef}; Resolution: Please check expression syntax)
Query parameter looks like this:
incase the image doesn’t work:
Query parameter | Query parameter value
query | encodeURIComponent(‘select * from mytable where id < 1000’)
- ptaylor5 years agoEmployee
It is not necessary to use encodeURIComponent. The REST Get snap will properly encode the query parameter values. Can you please show the full configuration of your REST Get snap?
- ptaylor5 years agoEmployee
I also have to say that providing a REST service which accepts a SQL command to execute against your database seems like a rather significant security vulnerability.