On the other hand Sharepoint 2013 comes with a new REST interface that enables us to access and use its resources.When we combine these two new features we get powerful new ways for using our SharePoint workflows.
In this post I will show you how you can use this new action to POST new data to your SharePoint site.
I have created a SharePoint list named WorkflowItems to use for example. We will create items in this list from a workflow using SharePoint REST services. To keep it simple I will leave it with only one column (Title).
Now we can open our SharePoint Designer and create a new site workflow and call it WorkflowItemWizard.
In our new workflow first we will create couple of dictionaries. Dictionary is a new variable type in SharePoint workflows that is used for defining collections of key/pair values and is very important for the Call HTTP service action.
To create a dictionary add Build Dictionary action to you workflow. Using that action specify two new keys Accept and Content-Type and set the values for both of them to application/json; odata=verbose like in the image below
Set the output to a dictionary with a more meaningful name, call it "header". This dictionary will be used as a header for our request.
Next create another dictionary that you will call metadata and in it add a key called type with value SP.Data.WorkflowItemsListItem.
And finally you will need one more dictionary that will contain your request data. Call it parameters, add key __metadata and set its value to the previously created dictionary metadata
Now you are ready to call the web service. Insert action Call HTTP service.
The URL you will require will look like this:
and the HTTP method is POST.
right click on the Call HTTP service -> properties -> RequestHeaders and set it to your header dictionary.
Now you can deploy your workflow and run it. Once it is over you should have a new item created in your list.
From this example you can continue building your solutions, you can add more fields, or use other available REST services for updating list items or deleting them.
One of the biggest advantages using this method to create or update list items is it is not limited to the site in which you workflow runs. Using REST services you can now access and create items in lists on other sites.
If you want to know more about SharePoint 2013 REST you should check this out :
Programming using the SharePoint 2013 REST service
Also check this excellent post on getting data into your workflow from SharePoint using Rest services:
Calling the SharePoint 2013 Rest API from a SharePoint Designer Workflow