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.
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:
And you would like an extra parameter to be appended to the URL, for example:
$filter=userId eq 12
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:
In the example provided above, the value of the parameters argument would be:
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
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,