Saturday 8 August 2015

SharePoint 2013 REST API Get requests from the designer workflow.

SharePoint 2013 provides a completely new workflow engine, which has a new "Call HTTP web service" action that enables us to communicate with the web service from our workflow.

In this blog post, I will show you how you can use this new action method for a REST API GET request to a SharePoint list.

I have created a list "WebServiceList" and inserted dummy data into it as shown below.


Open SharePoint Designer 2013 and create a workflow attached to the list created above. Use the platform type as SharePoint 2013 workflow; otherwise Call HTTP web service method will not be available.
In our normal CSOM(Client Side Object Model), we call the REST API to get data back in JSON format. You need these headers as:

Accept: application/json;odata=verbose
Content-Type: application/json;odata=verbose

In the workflow add the "Build the Dictionary" action of above headers as:

Click on the three dots to add items to the dictionary.






Now, add the HTTP call web service method with type GET as given below:


Test your REST call in the browser as given below:

Add the header dictionary variable created just above to the web service and set the request type to "GET" as:


Then click OK.
Add the GET action, and now we will get the result from the response content variable as

Now get the CountItems of the Output variable (allTitles) from the get action.
Then take one variable and set it to "0" and insert Loop (Loop n times). Inside the loop again, add the GET action to get all titles from the variable JsonResult and log it. Add the Calculate action to add "1" to the loop index variable and then again set its value. Now end the workflow.
Complete workflow is given below


See the Tasks and Workflow History list details below; you will get the data fetched from the source list is logged in the history list.

Hope this will help you!


🚀"Happy Coding"🚀