Call Web API from SharePoint Online using httpsend workflow activity

SharePoint online call web api from visual studio 2015 workflow

This SharePoint 2013 workflow tutorial explains, how we can call a web API from a visual studio 2015/2017 workflow by using a httpsend activity in SharePoint Online.

In our previous articles, we discussed how to create a web API and deploy to Microsoft Azure using visual studio and also, we have discussed how to create a workflow as a SharePoint hosted add-in using visual studio 2015/2017 for SharePoint Online Office 365.

SharePoint deveopment training course

Call Web API using httpsend workflow activity in SharePoint Online Visual Studio Workflow

Follow below step to call web API using httpsend workflow activity in SharePoint Online Visual Studio workflow.

First, check out our the previous tutorial on how to create a workflow as SharePoint hosted add-in using visual studio 2017/2015.

Once the workflow is ready, First, we will create two variables.

  • varGetResponseContent (DynamicValue)
  • varResult (String)

If you will see the workflow variables it should look like below:

call web api from sharepoint
call web api from sharepoint

In the workflow, we can access the Web API Url through “HttpSend” workflow activity. Drag and drop a “HttpSend” activity from the Toolbox into the workflow designer interface.

Then in the HttpSend activity properties, choose below things:

  • Method– GET
  • RequestHeader:
  • Accept (Header Name): “application/json;odata=verbose” (Header Value)
  • Content-Type (Header Name): “application/json;odata=verbose” (Header Value)

The RequestHeader looks like below:

call web api from sharepoint online
call web api from sharepoint online

Uri: Put the Web API URL. In my case below is the URL:
https://mysharepointwebapi.azurewebsites.net/api/Default/MyAction?testParameter=Bhawana

ResponseContent: varGetResponseContent (Give the DynamicVariable which we have created in the above step).

The properties of HttpSend Activity looks like below:

call web api from sharepoint online workflow
call web api from sharepoint online workflow

Now next we will try to retrieve the value which we are getting from the web API.

Now add a GetDynamicValueProperty <T> from the toolbox like below:

httpsend activity sharepoint 2013 workflow
httpsend activity sharepoint 2013 workflow

First ,choose the Type as String in the GetDynamicValueProperty <T> activity like below:

httpsend activity sharepoint online workflow
httpsend activity sharepoint online workflow

Now in the GetDynamicValueProperty<T> properties, windows choose below properties:

Result: varResult (This is the string variable we have created at the beginning)
Source: varGetResponseContent (Same variable which we have used in ResponseContent in HttpSend activity)

call web api from visual studio 2015 workflow httpsend activitity
call web api from visual studio 2015 workflow httpsend activitity

Now we can add a WriteToHistory activity to write the variable value in the SharePoint Workflow History list. It looks like below:

call web api from visual studio 2017 workflow httpsend activitity
call web api from visual studio 2017 workflow httpsend activitity

The whole workflow looks like below:

call web api from sharepoint
call web api from sharepoint

Now our workflow development is ready. We can now deploy and see the result.

Right click on the project and click on Deploy. Once it is deployed successfully, open any list and from the ribbon, click on Workflow Settings -> Add a workflow.

In the Add workflow page, click on the Workflow Add-in app and then Select the workflow like below:

call web api from sharepoint online
call web api from sharepoint online

Then give a name for the workflow, choose the Task list and History list and check when you want to start the workflow, like below:

call web api from visual studio 2017 workflow httpsend activity sharepoint
call web api from visual studio 2017 workflow httpsend activity sharepoint

Once the workflow attached to a list, select an item and click on Workflow in the List tab in the ribbon. This will open the page to start a workflow. Click on the workflow link to start the workflow.

call web api from visual studio 2017 workflow httpsend activity sharepoint
call web api from visual studio 2017 workflow httpsend activity sharepoint

Once the workflow completed, you can see the status like below:

call web api from visual studio 2017 workflow httpsend activity
call web api from visual studio 2017 workflow httpsend activity

If you will check the details you can see the result like below:

web api SharePoint online
web api SharePoint online

You may like following SharePoint workflow tutorials:

Hope this will be helpful to call a web API from SharePoint Online using visual studio 2015/2017 workflow httpsend activity.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →