How to Connect to a Specific Folder Inside a Document Library Using REST API

This article demonstrates how to use the REST API connection to display files from a specific folder in a Document Library.


For this guide, we want to showcase files inside this PDF Guides folder:


SharePoint list with folders example


This is the result:


example file list with documents information


TABLE OF CONTENTS


Prerequisites


Step-by-step Tutorial

Follow the steps below to get started:


Step 1: Edit the ShortPoint Web Part

  • Go to the SharePoint page you want to use and click Edit.


Click Edit button on the SharePoint page


  • Close the Toolbox.


Hit the close icon to close the SharePoint Toolbox


  • Click the Edit properties icon.


Press the Edit properties icon to start editing ShortPoint


Step 2: Open the File List settings window


NOTE Before proceeding, make sure you already have the Design Element you want to use on your page. For this guide, we’ll use File List.
  • Click the Easypass tag of the Design Element.
  • Click the cogwheel icon.

open EasyPass tag and click the gear icon


The Design Element settings window will open.

Open settings window containing default content


Step 3: Open the Connect Window

  • Click the next icon.
  • Go to the Connect tab.
  • Select Configure.

Connect tab where the Configure button is located

The Connect window will open.

Connect window connection type options


Step 4: Copy and Prepare the REST API URL


Note Before proceeding, you must already have an existing Document Library with folders and files that you will connect to. To learn how to create a Document Library, check out Create a Document Library in SharePoint.


  • Copy the REST API URL:


https://site url/_api/web/GetFolderByServerRelativeUrl('Document Library Name/Target Folder Name')/Files


Substitute the items highlighted in red with your actual website URL, Document Library name, and the name of the folder you want to connect to. Here is an example of what the URL could look like:


https://yoursite.sharepoint.com/sites/marketingmaterials/_api/web/GetFolderByServerRelativeUrl('Guide/PDF Guides')/Files


Note: You can select specific fields/columns by adding the ?$select= query string to the end of your REST API URL and including the internal names of the columns.

For custom columns you created, you can use ListItemAllFields/CustomColumnInternalName

Here is an example REST API URL showing some default columns, as well as a custom column called "Description":

https://mycompany.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('Shared Documents/Folder Name')/Files?$select=Name,TimeCreated,TimeLastModified,Title, ListItemAllFields/Description,Author/Title&$expand=Author,ListItemAllFields

Check our our solution article ShortPoint REST API: Selecting, Filtering, Sorting Results in a SharePoint List to learn more.

Step 5: Paste the REST API URL, configure Advanced Settings, and Connect

  • Select REST API:


REST API button selected in the connect window


  • Paste the REST API URL you prepared in Step 3 in the field provided:


Paste the REST API URL in the REST API URL field


  • Copy the custom Map Results code.

Running the REST API URL on its own will pull data from your target folder, but you'll notice that the file extension is missing and the date returns in the wrong format. We'll use Map Results to reshape the data so both display correctly.


Copy this code:

return data.d.results.map(function(item) { item.Extension = item.Name.split('.').pop(); if (item.TimeLastModified) { var d = new Date(item.TimeLastModified); var mm = ('0' + (d.getMonth() + 1)).slice(-2); var dd = ('0' + d.getDate()).slice(-2); var yyyy = d.getFullYear(); var h = d.getHours(); var m = ('0' + d.getMinutes()).slice(-2); var ampm = h >= 12 ? 'PM' : 'AM'; h = h % 12; h = h ? h : 12; var hh = ('0' + h).slice(-2); item.FormattedDate = mm + '/' + dd + '/' + yyyy + ' ' + hh + ':' + m + ' ' + ampm; } return item; });
  • Scroll down and enable Advanced Settings.

Enabled Advanced Settings toggle

  • Paste the code into the Map Results field.

custom script pasted into the map results field

  • Click Connect.


Connect button in the connect window


Step 6: Map Items

  • Switch to the Items tab:


Items tab in the connect window to go to


  • Delete all default content:
  • Use the link icon to map the items you want to be shown inside the connected Design Element:
  • You can map the properties you want or follow what we’ve set up below:
    1. #Name - shows the name of the file as the title.
    2. #FormattedDate - shows the date and time the file was modified as the subtitle.
    3. #Extension - provides the file type.
    4. #LinkingUrl - attaches the link so that the document can be accessed.

link icon used to select the property to use in the connection


Step 7: Update and Save

  • Once satisfied, click Update:


Update button that should be pressed once connection is configured

  • Then, click the green checkmark.

Apply changes green button active in the settings window

  • Click the eye icon to see your page in real-time:


preview eye icon in the ShortPoint action toolbar


  • Click Save to apply all your changes:


Save button found in the ShortPoint action toolbar


That’s it! You can now connect to a specific folder and showcase all its files.


Related articles:

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 33 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