The Office 365 REST API provides a very useful way to interact with SharePoint data from any system able to create REST API requests. And one of those systems is our beloved Nintex Workflow for Office 365. In this post, we'll see how to use the Office 365 REST API to create SharePoint lists from a Nintex Workflow.
As in every REST API request, the first thing you need to do is to have a look at the reference documentation of that API, to understand the list of requests available and the values you need to provide for those requests. In our case, you can start with the SharePoint REST API documentation in this link.
Now, let's focus on the request we want to create. The following example, taken from the previous link, shows how to create a list:
With that, we know exactly all the information we need to get for our request. Creating a RESTful HTTP request in Nintex Workflow is easy if we know how to get that information, we just need to go through these 5 steps:
Those steps lead us to the following Workflow Design:
Let's go step by step and see it in more detail for our example:
We will create Dictionary variables for the Headers and the Body of the request and response. We also need variables for the Endpoint URL of the API resource and the Status Code of the response we'll get from our request. The metadataObject variable is a Dictionary that we need for an object to be included in our Request Body (we'll see it later in this post).
In our example we need to create headers for Accept and Content-Type to specify JSON as the format we'll be sending the request and the format we want to get the response. The rest of the Headers are not needed for a request coming from the workflow.
Notice that the first key-value pair, __metadata, is defined as an object in the API Reference Documentation. That's why we need, in a previous step, define another Dictionary variable, which I called metadataObject, and use it in the Request Body Dictionary. Here's how we define the __metadata object:
For the response body, we don't have to build the Dictionary. This variable will be where we'll be storing the JSON object of the response.
My recommendation, when building up REST API requests in a workflow is to create a workflow variable for the URL of the end point we're making the request, especially if the URL will contain dynamic values for the base URL, path and query parameters. And that's the case of our example with the RequestEndPoint variable. So, drag and drop a Set WF variable action to the canvas and use the Workflow Context on the right-hand side to pick up the URL of the Current site. After that, add the rest of the URL manually, as in the picture below: