While learning the SharePoint REST API, I created a little REST tester Content Editor Web Part. Later when I explored SharePoint 2013 Workflow REST calls I expanded the tool to include step by step instructions to add the calls to a workflow. After presenting this at the Cincinnati SharePoint User Group and at the Nashville SharePoint Saturday I decided to take the time to clean it up a bit and share it here.
What you will need:
- A SharePoint 2013 or later site.
- A web part page with a Content Editor Web Part.
- Permissions to access the content you want to access using REST!
- Some documentation:
- A REST Syntax wall poster: http://www.microsoft.com/en-us/download/details.aspx?id=41147
- REST API reference and samples: https://msdn.microsoft.com/en-us/library/office/jj860569.aspx
You can also download the file from the GitHub project.
This is the main screen.
This is partial list of the sample REST calls. A more complete list is at the end of this article, and I’ll be adding more over time.
The in the page test of a REST call.
The generated AJAX Code Sample
The SharePoint 2013 Workflow Steps for the Web Service Call
Steps to install to your SharePoint Site
- If your master page is not already loading jQuery, download jQuery (just about any version) and upload to the Site Pages library.
- Download the SharePointRESTtester.html file to your PC.
- Edit the file and update the line that loads jQuery to point your jQuery file or CDN.
- If your master page already loads jQuery, then delete the <script> block that loads the jQuery file.(the first line of the file)
- Upload the SharePointRESTtester.html file to your Site Pages library. (Copy the URL to the file.)
- Add a Web Part Page to your project:
- In the Site Pages library, click the FILES ribbon, click New Document and click Web Part Page.
- Enter a page name like "SharePointRESTtester".
- From the library dropdown select Site Pages.
- Click Create.
- Click Add a Web Part.
- Add a Content Editor Web Part.
- Click the web part's dropdown and click Edit Web Part.
- Enter or paste the path to the SharePointRESTtester.html file.
- Click OK and then in the ribbon click Stop Editing.
- You should now see the tester. Click the dropdown and you should see data in the boxes. If not, then the jQuery library did not get loaded.
- Add to your Quick Launch or your Follow list!
To use the tester…
- Select a sample from the dropdown, or enter your own URL, Method, Header JSON and if needed, the Body JSON.
- Find the Do It! button. The first check box will actually run the code. *** Warning Will Robinson, stuff could get added, changed or deleted! ***
SharePoint REST Examples for Queries
- Get information about the current site collection.
- Get information about the current web.
- Get the Regional Settings for the current web.
- Get the Time Zone for the current web.
- Get SharePoint's list of Time Zones.
- Get a list of all webs below the current web.
- Get the primary site collection administrator (Owner).
- Get the primary site collection Secondary Contact.
- Get a web's LastItemModifiedDate
- Get a list of lists from the current web. (all data)
- Get a list of lists from the current web. (Just the title)
- Get a count of items in a library.
- Get a count of items in a library. (Option #2)
- Get all items in a list/library.
- Get all items in a library with filename and path.
- Get a list folder's properties.
- Get a count of items in a list folder.
- Get all items in a list/library filtered by date.
- Get all items in web level recycle bin.
- Get selected properties of all items in web level recycle bin.
- Get all items in a list/library filtered by a range of dates.
- People Search
SharePoint REST Examples for Lists
- Create a new list
- Add a new item to a list
- Add a new folder to a list
- Delete an item from a list using ID
- Delete an item, to the Recycle Bin, from a list using ID
- Update an item using ID
- Delete a list
- Delete a list to the Recycle Bin
SharePoint REST Examples for Sites
- Create a new subsite.
- Delete a site (Warning Will Robinson! Does not go to the Recycle Bin!)
SharePoint REST Examples for User Profiles
- Get User Profile info about the current user.
- Get all User Profile properties for a user.
- Get User Profile info about a user's manager.
SharePoint REST Examples for Permissions
- Get a list of Role Definitions for a site.
- Get a list of Site Users. The ID is useful when setting permissions.
- Get a list of Site Groups. The ID is useful when setting permissions.
- Get a list of Site Groups by name.
- Get a list of Site Groups where name contains 'string'.
- Break inheritance on a subsite.
- Break inheritance on a list.
- Break inheritance on a list item.
- Grant permissions (Role Assignment) on a list.
- Remove permissions (Role Assignment) on a list.
SharePoint REST Examples for Filter Select and OrderBy
- Get a list of Site Users who are not Site Collection admins. Get selected fields and sort.
SharePoint REST Examples for SharePoint 2010 style REST - _vti_bin/ListData.svc
- Get a list of lists and libraries (EntitySets).
- Find list items greater than a date.
- Find list items between two dates.