How to use SharePoint Online CSOM from Azure Function


In previous post I showed how to create Azure Active Directory app and set up required permissions. Also, I provided the example of code that can be used to interact with SharePoint Online REST API using SharePoint CSOM. In this post I am going to apply a similar approach in order to provision SharePoint Online artifacts to the target site using Azure Functions.


You need to have Azure Subscription and Office 365 Dev Tenant. Refer to the previous posts in this category to get started with Azure Active Directory apps.


Microsoft advertises Azure Functions as a solution for easily running small pieces of code ("functions") in the cloud. You can write the code you need for the problem at hand, without worrying about a whole application of the infrastructure to run it. You can find more information about Azure Functions at Azure Functions Overview

Usually Azure Function is triggered by some event, processes event and outputs result to a destination. Our Azure function are going to be triggered by HTTP request, it will receive SharePoint site URL, and a list name as parameters. The function will create a new list on the site with given URL. I will also create a second function to provision one more list that I will use in one of the next posts.

Create new or use the existing resource group and search for Function App:

Then create a new function app:

Now create a new function called ProvisionSourceList:

Also we will need another function called ProvisionDestinationList to provision the destination list, use the same function type.

Create a new file called project.json and specify packages required by the function:

  "frameworks": {
      "dependencies": {
        "Microsoft.IdentityModel.Clients.ActiveDirectory" : "3.13.7",
        "Microsoft.SharePointOnline.CSOM": "16.1.5813.1200"

The next step is to upload the certificate that has been generated on the previous step, you should have the following files:

I am not going to copy-paste whole code here for both functions, because it is a bit lengthy. I published source code for these two functions to GitHub:

Make sure you uploaded .pfx certificate and updated the following parameters:

Make sure that you included all required packages. It is possible to test a function directly from the editor, just click on Test and specify required parameters:

It is also possible to test a function by invoking it by URL from browser, just copy paste a function URL and add required parameters to the query string, it should looks like this:{YOUR_AUTH_CODE_HERE}&siteUrl={YOUR_AUTH_CODE_HERE}&siteUrl=

As a result following lists have been created:

Source List 1:

Destination List 1:


In this post I have described how to create simple Azure Functions. Also, I showed how to work with NuGet packages from Azure Functions and how to use ADAL.NET to get access token from Azure Active Directory in order to use SharePoint Online CSOM. In the next post I am going to create another function that will be used for data transformation.