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 Create a Web API for SharePoint Online and Deploy to Microsoft Azure using Visual Studio (Step by Step tutorial) and also, we have discussed Develop SharePoint workflows using visual studio as SharePoint hosted App.
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:
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
- Accept (Header Name): “application/json;odata=verbose” (Header Value)
- Content-Type (Header Name): “application/json;odata=verbose” (Header Value)
The RequestHeader looks like below:
Uri: Put the Web API URL. In my case below is the URL:
ResponseContent: varGetResponseContent (Give the DynamicVariable which we have created in the above step).
The properties of HttpSend Activity looks like below:
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:
First ,choose the Type as String in the GetDynamicValueProperty <T> activity like below:
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)
Now we can add a WriteToHistory activity to write the variable value in the SharePoint Workflow History list. It looks like below:
The whole workflow looks like below:
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:
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:
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.
Once the workflow completed, you can see the status like below:
If you will check the details you can see the result like below:
You may like following SharePoint workflow tutorials:
- How to Trigger Sharepoint 2013 Designer workflow on a list item by calling REST API using jQuery?
- How to add edit task form URL inside SharePoint 2013 designer workflow email?
- How to send email to SharePoint group in visual studio 2015 workflow in SharePoint hosted add in SharePoint online?
- How to send email in visual studio 2015 workflow in SharePoint hosted add-in in SharePoint online?
- SharePoint designer workflow examples: Steps to create a Leave Request SharePoint designer workflow in SharePoint Online
- SharePoint designer workflows: Create your First Workflow using SharePoint designer 2013
- Errors were found when compiling the workflow. The workflow files were saved but cannot be run error in SharePoint online designer workflow
Hope this will be helpful to call a web API from SharePoint Online using visual studio 2015/2017 workflow httpsend activity.
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 SPGuides.com