SharePoint / SharePoint Online – Calling REST Service from SharePoint Designer Workflow

Hello All,

Today, we are going to discuss how REST service is called in from SharePoint Designer Workflow. For demonstration purpose I am accessing my Login Name through REST API from Site Users Information List.

Let’s get started!!

Prerequisites:

  1. Should have SharePoint Designer installed.
  2. Should know how to create list workflow.

Follow these steps:

  1. Create List Workflow.
  2. In the Stage 1 (You can rename Stage 1 to any meaningful name you want), add an action Build Dictionary or just click on orange bar and type build and press ENTER. It will add Build Dictionary See following figure.
Stage1_AddingAction
Figure .1 Adding action
  1. Click on “this” in the action to open Build A Dictionary and click Add.
Adding_RequestHeaders
Figure .2 Adding request headers
  1. We are going to add two request headers
  •           Name: Accept

            Type: String

            Value: application/json;odata=verbose

  •          Name: content-type

Value: application/json;odata=verbose

Request headers are required to send request to web server containing details of what the browser wants and will be ready to accept back from server. Do not make any mistake while writing value for above two request headers. A single mistake and you will not get output. Click Ok.

  1. Create output variable. Name it whatever you want. In this case RequestHeader.
  2. Now add action Call … Http web service
  3. Click on “this”. It opens Call HTTP Web Service window as follows. Click on three dots next to the text field provided below Enter the HTTP web service URL.
Calling_WebService
Figure .3 Calling web service
  1. It opens String builder dialog. Click on Add or change lookup. Next dialog will be opened is Lookup for String. Select Data Source as Workflow Context and Field from source as Current site URL and finally click Ok.

For reference please have a look to following figure.

Creating_LookupString
Figure .4 Creating lookup string
  1. Complete url as shown in the following figure. i.e. “SiteUrl/_api/web/siteusers/getbyid(10)” here I am applying filter by using getbyid(10) where 10 is my user id.
Complete_URL
Figure .5 Complete URL
  1. Right click on Call action and open Select proper variable name against their Parameters. Refer following figure. And click Ok.
Web_ServiceProps
Figure .6 Setting web service properties
  1. If you want to check response code value, log response code variable using Log to History List action
  2. Add Get Click Item by name or path and then click three dots next to it. In the string builder type d/LoginName. Select response content, which is collection of data requested by you. Select or create output variable.
Getting_Results
Figure .7 Getting Results
  1. Log output variable. Follow the same procedure as we did in step 8 or simply click “fx” symbol. Just this time select Workflow Variables and Parameters as Data Source and select your variable you created as output variable, in this case Output. Click Ok.
  2. In transition to stage select End of Workflow.
  3. Save and Publish.
  4. Here I am starting workflow manually. You can choose any option among three options available.
  5. Check the output below.
Output_Workflow
Figure .8 Output of Workflow
  1. Highlighted by yellow marker is our output (Login name).

This is how REST service is called from SharePoint Designer Workflow.

References:

http://www.c-sharpcorner.com/article/calling-rest-api-from-a-sharepoint-designer-workflow/

Thanks for reading 🙂

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.