How to work with web service using “Call HTTP Web Service” action in SharePoint Designer 2013


Hello all, my name is HyongGuk Kim, a Senior Program Manager on the SharePoint Designer team.

In this blog I’m going to talk about how we can easily write a SharePoint 2013 workflow which consumes public or commercial HTTP (REST) web service and how we can simply make it run as a service that sends daily emails by looping.

As you can see in the below video clip, we will build a site workflow named "eBay Daily Deals", which will read the daily deal information from eBayTM , create deal items in a SharePoint Promoted Links list, and then sends emails to people who want to receive this deal information.

Working with web service using Call HTTP Web Service action


Since the "eBay Daily Deals" workflow is a site workflow, the first thing you have to do is to create a new SharePoint 2013 site workflow. Once the site workflow is created, you simply add three stages, name them properly, and then link them using Go To actions.



Stage 1

Name Stage 1 “Get eBay Daily Deals” and then add four actions and one Loop block, as shown in Figure 1.


Figure 1. Workflow stage 1


The first action we added is a Call HTTP Web Service action. The HTTP URI is set to and the HTTP method is set to “GET”. It would have been great to just use one of eBay’s REST web services which returns JSON but due to an annoying header inside eBay's REST web service outcome we had to use an extra transformer web service (Note that there are a couple of transformer services available. In our case we used a service from which calls eBay's another REST web service which returns XML and returns clean JSON objects to us.

In the "Call HTTP Web Service" action statement we do not set RequestContent or RequestHeaders parameter because we don’t need to. We are only interested in the output of that web service. By simply setting the response parameter to a variable ResponseContent, the output of this web service call will get stored in the variable ResponseContent, which is a dictionary type variable.


The JSON output of the transformer web service which called eBay's XML web service looks like this:




{"ItemId":"221065015062","EndTime":"1341845999000","PictureURL":"http:\/\/\/00\/s\/NDI4WDUxMA==\/$(KGrHqJHJBwE8+9eOVMzBPZ1lhNt!g~~60_1.JPG","SmallPictureURL":"http:\/\/\/00\/s\/NDI4WDUxMA==\/$(KGrHqJHJBwE8+9eOVMzBPZ1lhNt!g~~60_1.JPG","Picture175Url":"http:\/\/\/00\/s\/NDI4WDUxMA==\/$(KGrHqJHJBwE8+9eOVMzBPZ1lhNt!g~~60_1.JPG","Title":"Acer ICONIA 7in Tablet 8GB WiFi","Description":"N\/A","DealURL":"http:\/\/\/5000101083_Acer_ICONIA_7in _Tablet_8GB_WiFi","ConvertedCurrentPrice":"139.99","PrimaryCategoryName":"Computers\/Tablets & Networking:iPads, Tablets & eBook Readers","PrimaryCategoryId":"171485","Location":"Miami, Florida","Quantity":"128","QuantitySold":"372","MSRP":"299.99","SavingsRate":"53%","AutoPay":"true","Hot":"false","Tier":"0","PriceDisplay":"MSRP"},

{"ItemId":"271012700385","EndTime":"1341845999000","PictureURL":"http:\/\/\/00\/s\/MzYwWDM2MA==\/$(KGrHqR,!ioE-w!y!T--BPto5nEk0!~~60_1.JPG","SmallPictureURL":"http:\/\/\/00\/s\/MzYwWDM2MA==\/$(KGrHqR,!ioE-w!y!T--BPto5nEk0!~~60_1.JPG","Picture175Url":"http:\/\/\/00\/s\/MzYwWDM2MA==\/$(KGrHqR,!ioE-w!y!T--BPto5nEk0!~~60_1.JPG","Title":"Sylvania Wireless CE 7-Inch Smartbook - SYNET7WIC","Description":"N\/A","DealURL":"http:\/\/\/5000101099_Sylvania_Wireless_CE_7_Inch_Smartbook___SYNET7WIC","ConvertedCurrentPrice":"49.99","PrimaryCategoryName":"Computers\/Tablets & Networking:Laptops & Netbooks:PC Laptops & Netbooks","PrimaryCategoryId":"177","Location":"US","Quantity":"1307","QuantitySold":"693","MSRP":"199.99","SavingsRate":"75%","AutoPay":"true","Hot":"false","Tier":"0","PriceDisplay":"MSRP"},





    {"SectionTitle":"Emergency Preparedness","Item":[

{"ItemId":"200687021159","EndTime":"1341845999000","PictureURL":"http:\/\/\/00\/s\/NDI5WDUwMA==\/$(KGrHqV,!p0E-vF(Fmt0BP7iH6)M6g~~60_1.JPG","SmallPictureURL":"http:\/\/\/pict\/200687021159_1.jpg","Picture175Url":"http:\/\/\/pict\/200687021159_1.jpg","Title":"DuroMax 1500 Watt Portable Pull Start Gas Power Job Site Electric Generator","Description":"NA","DealURL":"http:\/\/\/5000099668_DuroMax_1500_Watt_Portable_Pull_Start_Gas_Power_Job_Site_Electric_Generator","ConvertedCurrentPrice":"179.99","PrimaryCategoryName":"Home & Garden:Tools:Generators: Home-Use","PrimaryCategoryId":"46412","Location":"La Verne","Quantity":"302","QuantitySold":"228","MSRP":"299.99","SavingsRate":"40%","AutoPay":"true","Hot":"false","Tier":"0","PriceDisplay":"MSRP"},

{"ItemId":"370622857968","EndTime":"1341845999000","PictureURL":"http:\/\/\/00\/s\/MTAwMFgxMDAw\/$T2eC16h,!)0E9s37IeSMBP7IWFtFqw~~60_12.JPG","SmallPictureURL":"http:\/\/\/pict\/370622857968_1.jpg","Picture175Url":"http:\/\/\/pict\/370622857968_1.jpg","Title":"Dorcy High Beam LED Aluminum Flashlight 100 Lumens Water Resistant 41-4287","Description":"NA","DealURL":"http:\/\/\/5000099680_Dorcy_High_Beam_LED_Aluminum_Flashlight_100_Lumens_Water_Resistant_41_4287","ConvertedCurrentPrice":"11.99","PrimaryCategoryName":"Sporting Goods:Outdoor Sports:Camping & Hiking:Flashlights, Lanterns & Lights:Flashlights","PrimaryCategoryId":"16037","Location":"Altatac USA","Quantity":"1899","QuantitySold":"1113","MSRP":"49.99","SavingsRate":"76%","AutoPay":"false","Hot":"false","Tier":"0","PriceDisplay":"MSRP"},



By the way, to handle each internal item we could also have used a DealItems variable so that we can put our action statement like “Get ([%Variable: Index%])/Title from Variable: DealItems” to get item’s Title property. However, just to make it things simple and to show a clear structure of deal items inside web service output, I put full path to access item’s properties. So having the statement like “Get EbayDailyDeals/Item([%Variable: Index%])/Title from Variable: ResponseContent“ (not Variable: DealItems) will retrieve Title property of an item. For more information on using dictionary type please refer to the links provided at the bottom of this blog.


Figure 2 shows how we retrieve all the different properties of each internal items.


Figure 2. Retrieving properties of deal items and creating promotion link items


With the Get item from Dictionary action we store every property of each deal item into a workflow variable and then use them when we create a list item at the later part of Loop block. Most of variable types we are using in this "retrieve" process are of type string but you can notice that we are using other types too.

For more information on using dictionary type please refer to the links provided at the end of this blog.


Figure 3. Local variables


We also use the Replace String action to work-around a SharePoint limitation where we can't use ',' or '!' characters in a URL type data.


And at the end of the Loop block there are two Step blocks where we build the Email content and increment the index variable by one. The two main scenarios of this workflow are to create list items using the outcome of the eBay web service and then to send Emails to people who want to receive "eBay Daily Deals" information. As such, we are building an HTML fragment inside the Loop block as shown in Figure 4.


Figure 4. Two steps in Loop block


You can see that the workflow variables we used to create the list items are all being reused in building the HTML fragment as shown in Figure 5.


Figure 5. Building HTML fragment for Email body



Stage 2

The workflow logic in Stage 2 is exactly the same as the workflow logic in Stage 1 except for one statement which calls web service in Stage 1 (see the circled statement in Figure 6). As such, you can easily create Stage 2 by just copying and pasting the content of Stage1 into Stage 2.

Stage 2 will read an additional section within the eBay’s Daily Deals web service output. Therefore, we can use the same logic but use a different path when trying to retrieve the Item array from the above big JSON output.


Figure 6. Workflow stage 2


And this means we need to use a different path for accessing items in “MoreDealsSection”, as shown in Figure 7.


Figure 7. Getting more deal items in MoreDealsSection


Everything else is exactly the same.



Stage 3

In Stage 1 and Stage 2 we created list items and also built the HTML fragments to use when sending Emails later. Stage 3 is the place where we will send emails and thus has only one action, the Send Email action as shown in Figure 8. “Subscribers” is the SharePoint group where all the site members who want to receive Daily Deals Email are added as members.


Figure 8. Workflow stage 3


You can compose a complete Email body in HTML in the property grid dialog of the Send Email action as shown below. Since we already have a complex HTML table code fragment in the variable EmailContent, we only have to put a few wrapper tags around that variable lookup, as shown in Figure 9.


Figure 9. Building a complete Email body


This is it! You are now completely ready to publish and start this workflow.

Just make sure you have an "eBay Daily Deals" list in your site and it should be a "Promoted Links" type list which is a new cool list type in SharePoint 2013. You can easily find this list app when you click Add an app from the Settings link which is in the right top corner of your site root page.




Start the Workflow

When you start this workflow you will see the workflow creating eBay Daily Deal items in your "eBay Daily Deals" list and you will also notice that you have Emails being sent from this workflow.


Figure 10. eBay Daily Deals promoted links list



Figure 11. Email sent from workflow



Loop Back?

We saw how we can build a good site workflow which sends Email with eBay Daily Deals information in it. What if we want to receive this email “every day”? Will it be possible to have this workflow run repeatedly every 24 hours?

Yes! As shown below by adding a Pause for Duration action and changing the target of the Go To statement inside of Stage 3 to point back to Stage 1, this workflow will now work like a service which will retrieve eBay's Daily Deals items and will then send these deals as Email every day.

Sounds fun, right?


Figure 12. Looping back to the beginning




Here are references where you can find more information on the dictionary type and workflow actions which handle dictionary variables and HTTP web services.


SharePoint Designer 2013 Help Content