Consuming rest api - problem with formatting query parameter

Hello,

I am using version 11.6.27 Build 11455, and I am working on a web app.

I am trying to consume a single method in a rest api. I am using a GET method, and the URL has the form

http://api.example.net/Portal/rest/ServiceName/Method()?$filter=id eq '12345'

The correct result is returned when I put the url in a web browser, and when I consume a single method via a REST integration in outsystems. The problem comes when I create an input variable instead of hardcoding the id in the url. For example:

http://api.example.net/Portal/rest/ServiceName/Method()?$filter=id eq '{id}'

In the 'Test' tab, if I set id = 12345, I still get the correct response. Similarly, if I remove the single quotes from the url and set id = '12345', I also get the correct response in the 'Test' tab. 

However, using the url with the single quotes, if I set id = Session.id, where Session.id has the data type Text, and is set to "12345", I get an OK response from the server that starts with HTTP/1.1 200 OK, but the body of the response is empty. 

If I use the url without the single quotes, and set session.id = '12345', I get a 400 BadRequest status response. 

I have tried several other variations - some return 400 BadReqeust status, while others return 200 OK status but an empty response body. Can someone see what I am doing wrong. I suspect it has to do with how the API expects single quotes surrounding the query, and text in outsystems is defined using double quotes. 


Thanks for any insights anyone may have,


Ryan

Hi Ryan,

I have tried the above url in postman but it's not working. Can you please share  the result of success and failure?

Regards,

Manish Jawla

Hi Ryan,

You could enable Full Logging for the integration services so that you see what the transmitted URL actually is including all headers and such. 

Kilian wrote an quick post on how to enable this: https://www.outsystems.com/forums/discussion/33272/setting-logging-level-of-a-rest-api/

Be sure to disable it when your done. These kind of loggings can fill up the database rather quickly. 

Hi Vincent,

Looking at the full logs was very useful. Thank you for posting a link to the instructions to elevate the logging level. I found that characters not allowed in URL's are escaped differently in the two situations below, which seems like a bug in OutSystems. I solved the problem by using the escaped version of the URL in situation 1, and replaced the hard-coded value 12345 with {id}

Situation 1: no input parameter, id is hard-coded as 12345

http://api.example.net/Portal/rest/ServiceName/Method()?$filter=id eq '12345'

Situation 2: input parameter id has data type text and has value of 12345

http://api.example.net/Portal/rest/ServiceName/Method()?$filter=id eq '{id}'


Vincent Koning wrote:

Hi Ryan,

You could enable Full Logging for the integration services so that you see what the transmitted URL actually is including all headers and such. 

Kilian wrote an quick post on how to enable this: https://www.outsystems.com/forums/discussion/33272/setting-logging-level-of-a-rest-api/

Be sure to disable it when your done. These kind of loggings can fill up the database rather quickly. 



Can I get some more help with this? I thought I had it all figured out, but apparently I don't (although the logging advice was very useful).

When I configure my app to consume an api method (see screenshot below), and click test, the correct response is received.


However, if instead of passing 12345, I pass TestVar, where TestVar is a variable of type text, and is set to "12345", the request returns with no information and the error log in service studio gives the following error:

Could not assign 'System.Byte[]' to 'tblName.ROW_VERSION'... Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

The service is querying a sql server database, and tblName.ROW_VERSION is a timestamp field in a table the service is querying. I don't understand why this error is being thrown. Can anyone help me gain some insight into what is going on?

Hello Ryan,


Did you test in runtime passing "'12345'" as the value of TestVar?

I mean, put in the text variable '12345'  and not using the single quote in the URL?

Ryan,

Can you also post a working URI and a not working URI that you get from the integration logging? Please specify the data type of the input clearly since this is still a bit confusing for me. 

Kind regards,

Vincent