Microsoft Flow team improves their product continuously, as well as other third party vendors. Unfortunately, there are still some gaps in its functionality, especially SharePoint related. That is why I thought it would be a good idea to cover some functionality by Azure Functions and make it easy to use and extend.
As an example, I have implemented a function that allows you to create a new SharePoint folder from your Microsoft Flow.
At the end of this post, you will have Azure Function that is hosted in your Azure and a new Microsoft Flow action. It doesn’t require any programming skills. At the same time, if you are a programmer, you can still customize and extend it. All sources will be hosted in your GitHub repository. Feel free to add new functions and submit a pull request.
Azure Functions can pull source code from a GitHub repository. Thus, you can easily reuse Azure Function from my repository in your Azure environment. I will not describe details of implementation of the Azure Function here. It is a topic for other post. I will show how to use my SharePoint folder creation Azure Function below. Just take it and use.
Steps to use Azure Function in your Microsoft Flow:
- Fork my repository on GitHub
- Configure new Azure Function to pull code from your GitHub repository
- Register custom connector in Microsoft Flow
- Use Azure Function in your Flow as you would use any other action
Fork repository on GitHub
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
The only prerequisite here is the creation of a GitHub account if you don’t have it yet. Then navigate to my repository https://github.com/plumsail/plumsail-sp-functions and click a “Fork” button at the right top corner.
Now you have your personal copy of Azure Functions repository
Configure new Azure Function to pull code from a GitHub repository
Open your Function and navigate to Platform features -> Deployment options.
Click ‘Setup’ and choose GitHub as a source. Sign in to your GitHub account and pick ‘_sp-azure-function_s’ repository. Click OK:
Now you need to wait for a minute. Code from GitHub repository will be published to your Function App.
Once it happens you will be able to see new Function under ‘Functions’ section:
Then you need to enable CORS (cross-domain requests) for https://flow.microsoft.com. It will allow Microsoft Flow to access the definition of our Function and call it.
Navigate to Platform features -> CORS:
Add https://flow.microsoft.com to the list of allowed origins and click ‘Save’.
Then you need to add your SharePoint Online account name and password to application settings. The function will use them to create a new folder.
Scroll down, add ‘SharePointUser’ and ‘SharePointPassword’ properties and save the settings:
Register connector in Microsoft Flow
Now we need to let Microsoft Flow know about our Function. Azure Function has a Swagger definition that describes API of a function. You can feed this definition to a Microsoft Flow connector. Thus, it will know how to call our function from a Flow.
First of all, we need to prepare swagger definition. Navigate to ‘API definition’ section of your Function App. You will see an XML structure representing swagger definition. You need to replace one word in your definition, it is an address of your Flow App:
In the picture above I replaced ‘spfunction’ with ‘sharepoint-function’ (name of my new Function App).
Note: Looks like now Microsoft Flow requires ‘operationId’ property in the swagger definition should not contain any spaces. If you have spaces, as I have in the picture above, remove them. Thanks @justinkobel for comment.
Click ‘Save’ and copy API definition URL somewhere.
Navigate to your Microsoft Flow account (https://flow.microsoft.com). Open Connections:
Create a new Custom Connector using the API definition URL that you copied earlier:
Click ‘Continue’ and fill in ‘Label’ property. ‘Label’ is a display name of an API key that will be displayed in Microsoft Flow Connection. I called it ‘Key’:
Click ‘Continue’ and ‘Create connector’ buttons.
Once you created custom connector you can use a function in your Microsoft Flow.
Use Azure Function in your Microsoft Flow as you would use any other action
Create a new Flow and search for ‘SharePoint Create Folder’. You will see a new action available:
Once you added it to your flow, you will be prompted for an API key:
An API key can be copied from your Azure Function settings like this:
Now you can specify parameters for the action:
- sharePointSiteUrl — SharePoint site URL
- baseFolderServerRelativeUrl — Server relative URL of a folder where you want to create a sub-folder
- newFolderName — Name for a new sub-folder
Run your Flow:
That is all! Now you have a new action in your armory. It may seem a bit tricky initially. But it has a huge potential for extension of you Flows. Now you know how to use Azure Functions to communicate with SharePoint.
Azure Function is hosted in your Azure. It is completely under your control. Code of the function is in your GitHub repository.
If you are an IT Pro, take and use it without modifications. If you are a developer feel free to contribute and add other functions and share them with the world!
Please share ideas for new actions in comments. If this article was helpful to you, please do hit the 💚 button below. Thank you!