How can we help you today?

Modify URL Parameters Function for Your ShortPoint REST API Connection


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.


Issue


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.


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!


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 31 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more