Welcome to Part 3 of this Dictionary series. The previous two posts can be found here:
Dictionary Part 1 - Manually Creating a Dictionary
Dictionary Part 2 - Query XML results into a Dictionary
There are a number of web services that come with SharePoint online. Both ASMX and REST services. In this post, we're going to look at making a query to a SharePoint REST services, store the results into a Dictionary variable and parse those results.
The service we will call, is the lists service. The url will look like this : http://hsiteurl]/_api_web/lists
This will give us a bunch of data about every list in that site. In this example, we want two pieces of information. The List name and the List template it was based off of.
Calling the Web Service
The HTTP Call Web Service action make it quite easy to call the lists service and it lets us store the results in a Dictionary variable.
Notice the dynamically generated URL for the web service. That means that you can take the attached web service and import it into O365 site without having to modify it. Although, I don't know why you'd want that, since it doesn't do all that much.
We store 2 pieces of information with this action. The response content, which will come back from a REST service in JSON format, but we are storing it in a Dictionary variable. The last piece is the Response Status Code, because we want to check that to make sure we get a valid status.
Want to learn more about SP Rest Service? - Get started with the SharePoint 2013 REST service
Ready to Parse the Data?
Not quite. What we have the raw dictionary. Inside it is what I would call a dictionary in a dictionary . We need to pull out that sub-dictionary from the key "value" and store it in another variable that we will then be able to parse.
Getting the List Title and Template
We will be parsing the dictionary data a little differently than in the last post. Instead of a Loop N Times action, we will use a Loop with Condition action. The result is the same, but I wanted to make sure everyone was aware that there are usually many ways to accomplish the same thing.
We will have an index variable that we will increment inside the Loop, and the loop will be configured to loop while the index is less than the count of the items in the dictionary.
Assuming we have the Count already, here is the Loop action configuration:
You'll notice it looks a little different to the Loop N Times action.
Inside the Loop, we have a Parallel Branch action with 2 branches. Each branch is going to pull out data from the dictionary.
But, we need to be aware that the Get an Item from a Dictionary action is a little tricky now that we are parsing data in a dictionary based of JSON data.
To get the data, the path will look like this:
({Variable:numIndex})/Title
({Variable:numIndex})/BaseTemplate
Finally, we need to do a calculation to increment the index, so that we get the next lists' data.
Conclusion
The one thing I found, was that when dealing with JSON, it's not easy to see what the response contains. If you do, you can email yourself the Web Response dictionary and that should give you an idea of how to build up the Get Item paths.
If you have any questions or comments, please post your comments below.