Azure Functions are a great and easy way for implementing and automating tasks for your SharePoint Online environment. You could use it for various tasks like implementing scheduled jobs (timer jobs), elevating permissions via an API call to fetch/create data, …
Starting to create new Azure Functions is simple with the Azure Functions project template in Visual Studio.
But there is an issue, once you created your project and want to add the SharePointPnPCoreOnline dependency to the project. You will notice that the installation is failing. This has to with the Newtonsoft.Json dependency that is used for the Azure Functions SDK is older than what SharePointPnPCoreOnline dependency requires.
The Azure Functions SDK currently has a dependency set to 9.0.1, but SharePoint PnP Core requires at least 10.0.3. Luckily the solution to fix this is very easy and is also documented on the Azure Functions SDK GitHub page. All you need to do is to manually install another Newtonsoft.Json version.
Read more about it on: loading a different Newtonsoft.Json version
Installing a newer Newtonsoft.Json dependency version
The solution to overcoming this issue is by first manually installing a newer version of Newtonsoft.Json via NuGet. Be sure that the version you are going to install equal or higher than 10.0.3.
In my project, I used version 12.0.1 of Newtonsoft.Json.
Installing SharePointPnPCoreOnline dependency
Once Newtonsoft.Json is installed, you can proceed with installing the SharePointPnPCoreOnline dependency to your project.
Running Azure Functions with SharePoint PnP core
Now that all the dependencies are installed, it is time to test it out.
Here is the result of the HTTP request function.