cancel
Showing results for 
Search instead for 
Did you mean: 
antonkhrit

How to call SharePoint from Microsoft Flow with the help of an Azure Function

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:

  1. Fork my repository on GitHub
  2. Configure new Azure Function to pull code from your GitHub repository
  3. Register custom connector in Microsoft Flow
  4. 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 Azure portal (https://portal.azure.com) and create Function App according to Azure documentation.

 

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-functions’ 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).

 

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:

Conclusion

 

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. This post was originally published in Plumsail blog.

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:

  1. Fork my repository on GitHub
  2. Configure new Azure Function to pull code from your GitHub repository
  3. Register custom connector in Microsoft Flow
  4. 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 Azure portal (https://portal.azure.com) and create Function App according to Azure documentation.

 

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-functions’ 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).

 

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:

Conclusion

 

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. This post was originally published in Plumsail blog.

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/