Retrieve content | Create content | Update content | Other actions |
|
|
|
|
In many cases, the actions available to retrieve content will suffice. However, there are times, where you may need to go beyond these actions to access your data. One such example is updating the name and URL of a link in a list or library item.
Send HTTP request to SharePoint Action
One of the actions mentioned above is the Send HTTP request to SharePoint action. This action enables you to interact with most aspects of your SharePoint Online environment (assuming your Flow account has the right permissions). The other actions are more specific in their functionality.The Send HTTP request to SharePoint action leverages the SharePoint REST service to achieve this using an extensive set of Create, Read, Update, and Delete (CRUD) operations.
Example 1: Updating Links
Let's look at a simple example of how to use the Send HTTP request to SharePoint action. Suppose you have a list, where you want to store my favourite links. For each link, you want to capture the following information:- Title - description of my link
- URL
- Link name - a short name
Using the OOTB Create Item action, you not able to set the Link name property on the link
As a result, when you create the item, the link URL and name will be set to the URL. Clearly, not what you were hoping to do.
Now, instead of using the Create Item action, if you use the Send HTTP request to SharePoint, you can see how you can provide the additional information to properly set the link name.
There are a number of parameters required for this action that are standard in making REST calls.
- Site Address - the site collection you are working in (the Flow account needs access to it)
- Method - what type of RESTful operation will you be performing?
- GET - retrieve content
- POST - create some content
- PUT - update content
- DELETE - delete content
- PATCH - make partial updates to content (e.g. only a few fields)
- Uri - the URL to the entity on which you will be performing the action
- Headers - contain important information to help you resolve issues with the requests
- Authorization - Carries credentials containing the authentication information of the client for the resource being requested.
- WWW-Authenticate - This is sent by the server if it needs a form of authentication before it can respond with the actual resource being requested. Often sent along with a response code of 401, which means ‘unauthorized’.
- Accept-Charset - This is a header which is set with the request and tells the server about which character sets are acceptable by the client.
- Content-Type - Indicates the media type (text/html or text/JSON) of the response sent to the client by the server, this will help the client in processing the response body correctly.
- Cache-Control - This is the cache policy defined by the server for this response, a cached response can be stored by the client and re-used till the time defined by the Cache-Control header.
- Body - contains the content to be used for the REST call. Each metadata field is applied a single value or array of values
In the example above, the Body is divided into 3 different metadata fields:
'__metadata': { 'type': 'SP.Data.SP_x0020_HyperlinksListItem' } | Defines the item as a list item in the SP Hyperlinks list. (NOTE: the space in SP Hyperlinks is replaced in SharePoint by _x0020_) |
'Title': 'Title' | Title of the list item |
'Link': {'__metadata': {'type': 'SP.FieldUrlValue' }, 'Description': 'Link name', 'Url': 'URL' }} | Link field value. As you can see, the Description and Url are provided separately and assigned values from the Flow trigger. |
Example 2: Retrieving items
When working with the Send HTTP request to SharePoint to retrieve items, you use similar settings on the action. Rather than using the POST method, you'll be using the GET method. As well, since you are only retrieving information, no body is required to complete the action. In the example below, the action will retrieve all the items in the SP Hyperlinks list.
Caveat
Whether you use the Get Items or Send HTTP request to SharePoint action to retrieve the items in a list, the items returned will be the same; however, there are slight differences in the JSON format returned, which you need to consider when iterating through the items to retrieve specific values.