If you tried to use the REST API connection type before, you may have noticed that it allows you to input a REST API URL or one will be selected if you select a local data source. This article sets out to explain how you can use the Modify URL parameters function to dynamically edit, add or remove parameters from the URL of your connection.


The Problem:


Let's say that you want to do dynamic manipulation of the URL parameters of the REST API connection. If you have selected a local data source, the connection URL will not be editable, and if you have selected a REST API connection, you will be able to edit the full length of the URL, but perhaps you would like to modify or add new parameters based on dynamic data, like the logged in user.



The URL Query Parameters are represented by the value beginning after the question mark (?) in the URL, which in our case would be:


?$select=Id,Title,Body


And you would like an extra parameter to be appended to the URL, for example:


$filter=userId eq 12


Since the URL is not directly editable, this functionality will allow you to use custom JavaScript code in order to extract the current parameters as a JavaScript string, manipulate it and reattach it to the URL before connecting.


The Solution:


We need to process the URL parameters so that the final URL becomes:


/sap/fiori/shortpointwidgetbeta/destinations/shortpoint-sharepoint_announcements/_api/web/lists/GetByTitle('Announcements')/Items?$select=Id,Title,Body&$filter=userId eq 12


This is where the Change Parameters Function in the Connect Tab comes in.

So what does this function do?

Before connecting to the REST API service, this function will be executed, allowing you to process the URL parameters string by adding, modifying or removing parameters.


This function has only one argument ( parameters ), which are the parameters extracted from the URL as a string. If you type nothing in the Change Parameters Function, it will simply extract the existing URL query parameters and perform no manipulation on them, the default value of this function being:


return parameters;


In the example provided above, the value of the parameters argument would be: 


?$select=Id,Title,Body


Since this argument is a string, we can perform string manipulation methods on it. In the simplest scenario possible, we would just need to concatenate the following:


$filter=userId eq 12


to the end of the initial string. That means we need to apply the following JavaScript code. Please note that we are adding an ampersand (&) since we now have multiple parameters, and has to be used as a separator.


parameters += '&$filter=userId eq 12';
return parameters;


The updated URL query parameters will be displayed at the top of the Change Parameters function once you click on Connect button:



Other use cases:



That's it, the new URL query parameters have been added to your original URL, so you now have more control when it comes to sourcing your data.


Hope that helps,

Happy connecting!