How can we help you today?

Modify the URL Path 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 path function to dynamically edit, add or remove directories in the URL path of your connection.


Issue


Let's say that you want to do dynamic manipulation of the URL path of the REST API connection and either add, remove or edit directories. If you have selected a local data source, the connection URL will not be editable, while 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 path directories based on dynamic data.


The URL path is represented by the value beginning after the top level domain (TLD) name, which in our case would be:


/sap/fiori/shortpointwidgetbeta/destinations/shortpoint-sharepoint_announcements/_api/web/lists/GetByTitle('Announcements')/Items


And you would like an extra directory to be prepended to the URL, for example:


/root


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


Solution


We need to process the URL path so that the final URL path includes the directory or directories we need, in our case:


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


This is where the Change Path 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 path string by adding, modifying or removing directories, or just performing JavaScript string manipulation methods on the string.


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


return path;


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


/sap/fiori/shortpointwidgetbeta/destinations/shortpoint-sharepoint_announcements/_api/web/lists/GetByTitle('Announcements')/Items


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:


/root


to the beginning of the string. That means we need to apply the following JavaScript code:


path = '/root' + path;
return path;


The updated URL path will be displayed at the top of the Change Path function once you click on Connect button:



That's it, the new URL path has been added to your original URL, replacing the old one, 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