Using Azure Logic Apps for Site Provisioning in Office 365 part 1

By | 2015-07-16

This post will describe a very simple flow for the creation of Site Collections inside a SharePoint Online tenant. I wanted to use some of the new Azure Apps that are available, in particular Azure WebJobs and Azure Logic Apps. I already wrote about the Logic Apps earlier.

The scenario/flow is fairly easy:

  1. User adds a List Item in a SharePoint List named Site Requests
  2. When this List Item is Approved (yes/no field 🙂 ) a Flow is started
  3. The Flow will
    1. Create a Site Collection
    2. Send a notification Email

In this post I am going to describe the part that will actually create a Site Collection in SharePoint Online. This is not an enterprise ready code implementation of it, just a sample to show it can be done.

This is how I wanted this part of the overall process to go:


A JSONObject will be send on a Azure Service Bus Queue.

An Azure WebJob will process Messages on this Service Bus and Create a SharePoint Site Collection.

First we create a Service Bus in Azure (via PowerShell).

Within this Service Bus we create a Queue:



For our WebJob to be able to read messages that are sent on the queue we need a Connection String. Go to the Configuration Page of the Queue. There you add a Shared Access Policy named WebJob. Provide Manage rights and Save:

azure-servicebus-siterequests-accesspolicy(Here I already added another Policy already I will need later.)

On the Dashboard Page of you Queue, you can see what the Connection String is by clicking the “View Connection String” button on the Right side of the Page. It will look like this:

Now we use the Azure WebJobs SDK and Visual Studio (2013) to create a WebJob Project. You will need the Connection String we just found and add it to the App.Config (for local testing)

The main of your WebJob looks like this now:

And we have Functions class, we will add our ProcessSiteRequests method which needs the following attributes to work with our Queue:

I am using Newtonsoft.Json to translate to and from Json strings to objects.

The TenantAdmin class just contains some CSOM and a SiteCreationProperties object to actually create a Site Collection. I left this out here.

Anyway now we deploy our WebJob to Azure. Once that is completed, we need to add the Connection String to our deployed WebJob too. Now we use the new (preview) Azure Portal to navigate to our newly deployed WebApp with our new WebJob. We use the Application Settings for the WebApp to add the same connection string we added to our App.config:


By the way, as part of any WebJob deployment, and per instruction of the Azure WebJob SDK, you will need to add the [AzureWebJobsDashboard] and [AzureWebJobsStorage] keys too, but you can find the howto for those in the SDK.

We wrote some code, we configured some Azure, now let us test this part of the overall solution.

You can easily create a Console Application in VS2013, add the Azure Service Bus SDK, make sure you add the Connection String again and you can send a simple JSON object on the Queue with this code:

If you have done it correctly, the message will be sent on the Queue.

And your WebJob will receive the JSON Object and start creating your first Site Collection.

You van monitor your Azure Queue and see a message being submitted.

You can monitor your Azure WebJob and see the method call actually executing.

For this, open the WebJobs Settings in the new Azure Portal, and click on the LOGS link. You will be presented with an overview of the calls that were made and other details:


Pro Tip when working with Azure Service Bus (and Queues): Get this tool: Service Bus Explorer

Next time, we create a Logic App that will use this Queue and WebJob. Stay tuned.

29 thoughts on “Using Azure Logic Apps for Site Provisioning in Office 365 part 1

  1. Pingback: Using Azure Logic Apps for Site Provisioning in Office 365 part 2 | Stef van Hooijdonk

  2. Tomasz Foltman

    FYI: Look like plenty of links and images are not working on this and other pages…

    1. stefvanhooijdonk Post author

      I know, had to migrate a couple of times, lost the images 🙁


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.