Calling Rest API From A SharePoint Designer Workflow

Introduction

In this article, we will implement an approach of calling a REST API in SharePoint Designer Workflow.

Scenario

Create a custom list, “IT,” and let’s say that we want to create a Workflow which returns the first one by using REST API, which is based on Dept. Filter, which shows Title Name.


Objective

Start SharePoint Designer 2013 and add a list Workflow on this IT list; make sure Workflow is a SharePoint 2013 Workflow.


In the screenshot given below, we need to look back at the XML generated in the Browser. Looking at the JSON output given below from our .getJSON() call, we find the values to show and highlight/copy XML name as we’ll need the exact value since jQuery is case sensitive.

https://serversitename/_api/web/lists/getbytitle('IT')/items?$filter=Dept eq 'RnD'

You should get something, as shown below.


Since the $json option is not supported in SharePoint 2013 REST API, to get the the response in a JSON format, you will have to update the Accept and Content-Type http headers of your Rest http call to be more specific.


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

Now, let’s get back to our Workflow in SharePoint Designer 2013.

Steps 1

We need to create the Request header and this is possible by using a Dictionary ->.

In the existing stage, type Build -> rename the variable dictionary as RequestHeader.


Steps 2

Click this and click Build your dictionary; add the Accept and the Content-Type headers.


Steps 2

Go to Action ->Core Action->Call HTTP Web Service option. Now, let’s focus on the Http request by adding a Call action.


Step 3

Click this and paste your http request.


Steps 4

Choose the Advanced Properties icon. In the Call HTTP Web Service Parameters dialog, click RequestHeaders dropdown, choose RequestHeader variable and click OK.


Step 5

In the Call action, click Response and associate the response to a new variable: JSonResult (of type Dictionary) and a new variable: ShowTitle(of type String).

After the Call action, add a new Get action.


Steps 6

Add a log activity and display the ShowTitle variable in the log.


Steps 6

The final stage should look as shown below. Publish and run the Workflow.


Steps 7

In the Workflow history, you should find Filter Title, which is shown below.


Up Next
    Ebook Download
    View all
    Learn
    View all