I need to be able to pass a list of values for a given parameter for a GET operation of a REST Service.
In OutSystems it is possible to send an URL encoded value for the available input parameter of a REST Service operation.
(In the following text the word "param" is replaced in URLs by "daram" in order to avoid an issue in the WYSIWYG that replace the "& para" by "¶")
eg : https://myURL.com/myService/myOperation?param1=value1&daram2=value2
When passing simple values for param1 and param2 everything works simply. But when there is the need to send multiple values for one of the parameter then it becomes not that easy.
Imagine that we need to be able to send the following request to the REST Service :
eg: https://myURL.com/myService/myOperation?param1=value1&daram2=value2&daram2=value3&daram2=value4
In the previous call we can see that the parameter "param2" can be sent multiple times. By design, Service Studio and OutSystems didn't provide a simple solution to solve the case.
What I've tried is to send the following value to the REST Service Action :
"value2&daram2=value3&daram2=value4", the value is build through a ForEach where we add the following part to the initial value : "&daram2=" + theNextValueInTheLoop, and so on.
When tested directly in Service Studio the call works perfectly and the service returns the expected response.
But when the service is called via an app. then OutSystems ( ... I mean the app) encode the value as follow :
https://myURL.com/myService/myOperation?param1=value1&daram2=value2%26param2%3dvalue3%26param2%3dvalue4
As we can see the "&" is encoded as "%26" and the "=" is encoded as "%3d" ... which is normal so far.
In order to solve this, I've added an OnBeforeRequest Action for the REST Service calls.
On this OnBeforeRequest Action, I've added a ForEach operation on which I call a DecodeURL Action in order to reassign the decoded value to the "CustomizedRequest.URLQueryParameters.Current.Value" value.
The expected behavior was to decode the "%26" and the "%3d". But this manipulation didn't worked as expected and the value was remaining URL encoded.
When debugging the app into Service Studio what we can see is that the value of the URLQueryParameters were correctly URL decoded, but still were remaining URL encode into the final service request.
I've tried to not use the DecodeURL Action and replace it with a simple Replace Action : Replace(MyEncodeValue, "%26", "&") and Replace(MyEncodeValue, "%3d", "="). Here, again same result : an encoded value sent to the REST Service.
To summarize the question is :
How to send an URL decoded value into a REST Service call of type GET where "&" and "=" are sent without being URL encoded ?
Hello Renaud,
Have you tried to use the URL Decode on the entire URL before the call?
If you modify your trainigs_list call to only accept the URL ( only a string) and assemble everything before you call the API and just send the decoded URL instead of all the params.
Hope it helps!
Paulo Rosário
Hello Paulo,
I tried your idea but without success but maybe I misunderstood your explanation.
Here is what I've done :
In the OnBeforeRequest action of the service I extracted each "Name=Value" keypair from the URLQueryParameters in order to manually assemble them and then finally compose a URLPath which contains the path and the parameters.
And in the assignment of the ForEach :
The URLPath is then URL decoded again to be 100% sure ;-) but the request fails even before being sent to the REST service. Below is the stack trace of the error.
Did I misunderstand your idea ?
For your information, the current version of OutSystems no longer allowed to send unencoded parameters in the URL. The system re-encodes everything even after a DecodeURL logic, whether for the Parameters or the URLPath ...
Have a great day,
Renaud
Hi @Renaud Diez ,
Apologies, I know it's too late to respond to your query but today me and one of my student came across the similar scenario in which we are consuming a rest API and we need to pass the dynamic parameter values to the API url query parameter.
We tried all the approach but getting the similar issue of %26 for & it got encoded during the processing.
Today, I found a work around for this, we have created a temp table to record the each user API request and store the dynamic url parameter values & name inside it and OnBeforeRequest we call the server action to get the values of those dynamic parameters and add them to custom request query parameter list. This solution is working fine for us and we are also deleting this data on OnAfterResponse.
You can modify this approach or you can use your own logic but by following this idea you can overcome the limitation of adding dynamic query parameters to api url.
I am attaching the sample .oap which I have created as a sample application just to proof & show how can you add dynamic query parameter to your api url, I used the dummy rest api just to showcase this use case and also the stack trace evidence to show you the full request which got created by using this approach.
Note: OnAfterResponse I am raising a exception just to capture the full log for API call which is not needed in your case.
I know it's a late post but it might help others to overcome this issue/limitation.
Thanks
Manish Jawla