Blog

Creating SharePoint List Items in Microsoft Flow Using a REST API

Creating SharePoint List Items in Microsoft Flow Using a REST API

I was recently creating a Flow when I realized that the “Create Item” and “Update Item” actions in Microsoft Flow would not allow me to set the value of a hyperlink field.

To overcome this, I used the “Send an HTTP request to SharePoint” action to create the item through a REST API.

I have used REST APIs on numerous occasions to overcome limitations of Microsoft Flow; however, I thought a quick instructional on how I did it would be useful as they can seem a little overwhelming to new users.

To begin, create a Flow and get to the step where you would normally use the “Create Item” action.

Create the next step, in the search bar type in “HTTP request,” and select “Send an HTTP request to SharePoint.”

MS Flow HTTP request

Next, fill out all the fields on the action.

When entering the Uri, make sure to replace ‘List Name’ with the name of the list you want to create the item in. If there are any spaces in the list name, replace the spaces with %20. In the example below, you will see that my list name is “Proposals Needing Review” so I entered _api/web/lists/getbytitle('Proposals%20Needing%20Review')/items

  • Headers: enter “content-type” for the key and “application/json;odata=verbose” for the value.

send http request to sp

  • Body: For the body enter the fields and values using JSON. For example:
    	{
    	“Field 1”: “Value 1”,
    	“Field 2”: “Value 2”
    	}
    	
    A couple of things to note:
    • You must place quotation marks around the field and value even if the value is entered using “Dynamic Content”.
    • A hyperlink field must be entered using the following format:
      “Hyperlink field name”:
      {
      
        “_metadata”: {“type”: “SP.FieldUrlValue”},
      
        “Description”: “Description Value”,
      
        “Url”: “Url Value”
      
        }
    • The last field and value must be:
      "__metadata": { "type": “SP.Data.MYLISTNAMEListItem" }
      In this example replace MYLISTNAME with the actual name of the list you are creating an item in and replace any spaces in your list name with “_x0020_”. For example, for my list titled “Proposals Needing Review” I have:
      "__metadata": { "type": “SP.Data.Proposals_x0020_Needing_x0020_ReviewListItem" }

Send HTTP request to SharePointYour Flow will now create items using the REST API and correctly populate the hyperlink field.

If you continue building your flow, you will realize that you are unable to reference fields from the “Send HTTP request to SharePoint" step as dynamic content.

For example, if I go to update the item using the “Update Item” action and try to pass in the item ID from the “Send an HTTP request to SharePoint” step, the only dynamic content is “Body.” We do not see any of the fields that we passed into the item like Title, ID, etc.…

update item in sharepoint

To access the fields, we need to parse out the fields we entered into the body of the request using the “Parse JSON” action.

To begin, run the flow. From the Flow results page, navigate to the “Send an HTTP request to SharePoint” step and expand it.

  • Scroll down to the Body section and copy everything in the field.
  • Paste it in a text editor to use later.
  • Now go back to editing the Flow and add a new step.
  • Enter jsoninto the search box.
  • Select “Parse JSON” from the list.

Choosing JSONIn the “Content” field select the Body output from the “Send an HTTP request to SharePoint” step.

selecting body outputUnder the “Schema” input select “Use sample payload to generate schema.”

generating schema In the popup that appears enter all the JSON you copied from body output on the Flow results page earlier.

parsing json load

When you are finished select “Done.”

If we try to update the item again using the “Update Item” action, we will see that all the fields from the item are now available as dynamic content under the “Parse JSON” step.

Now if we run our flow we can see that it correctly adds the item and populates the hyperlink field.

DMC's Digital Workplace Solution Team has extensive experience implementing Microsoft Flow solutions in a wide range of industries for a wide range of customers. 

Contact us today to get started on your next Microsoft Flow project. 

Learn more about DMC's Microsoft Consulting Services.

Learn more about DMC's Digital Workplace Solutions team.

Comments

Pablo
# Pablo
Thank you, very useful!

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts