Today we are going to create a Logic App to pass some sample JSON data, do some basic steps in it, call Azure function from Logic App, connect to Dynamics 365 in azure function, create or update records in Dynamics CRM with in azure function and then return some results back in Logic App and dome stuff in there.
First step is to create a new Visual Studio project of type Azure Functions in Cloud category
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76f578aad4f.png)
Select Http trigger as below
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76f5af527ec.png)
To keep things clean, create a new Class library project ‘LogicAppFunctionApp.Dynamics365Data’ in same solution as below
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76f6608e119.png)
Install following Nuget Packages in class library project
Microsoft.CrmSdk.CoreAssemblies
Microsoft.CrmSdk.XrmTooling.CoreAssembly
Then add a new class ‘CallDynamics’ in LogicAppFunctionApp.Dynamics365Data project
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76f89c45d74.png)
Now, go back to your Function app project ‘LogicAppFunctionApp’ and open ‘Function1’ class, below is how basic class looks like
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76f9141af6a.png)
We are going to pass JSON data in request and will retrieve it back as belowvar r = req.Content.ReadAsAsync ;
var jsonBodyResult = r.Result;
var result = CallDynamics.AddRecordToDynamics2(jsonBodyResult);
We need to create a new method ‘AddRecordToDynamics2’ in CallDynamics class
This is a method which will handle all our logic and JSON data
Let’s decide with JSON data we going to pass. In this example we passing simple JSON data as below
{
"company": "Rokhri Ltd",
"location": "Leicester, UK"
}
Now create a class with this JSON data, you can either create it yourself or use this http://json2csharp.com/ link
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76fc0b44bd2.png)
In our AddRecordToDynamics2 method we are going to use RootObject class to convert JSON
Our final class will look like below
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76ff8067bd2.png)
Function class
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76ffa93699d.png)
To debug it, run main project and copy URL as below
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76fda580c45.png)
Go to Postman and call this URL and pass dummy data
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76fe17055a6.png)
And you can debug your function
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76fe30604f5.png)
This will create a new account in Dynamic and return back results as below
![](https://365rack.com/wp-content/uploads/2018/08/img_5b76fed9c2925.png)
Up to this point our Azure function is complete and ready to be deployed in Azure and use with Logic app.
Now go to azure portal and create a new Function App and call it RokhriAzureFunction
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77009b76f13.png)
Go to Visual Studio, View, Cloud Explorer and connect to your subscription
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77011ae0cdf.png)
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7701664f384.png)
Here you will be able to see your newly created function app
Now we can deploy this function through VS but first lets download Published Profile
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7701e31f25c.png)
next go to LogicAppFunctionApp and right click to publish
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77020cd6455.png)
Then Import Profile
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77022582fce.png)
Once imported, you can publish your app
Next step is to create a Logic App
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77031b6bf91.png)
Once created, first step is to create HTTP request
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7703666140a.png)
Next select action of type Azure Function
![](https://365rack.com/wp-content/uploads/2018/08/img_5b770397a7364.png)
and you will see RokhriAzureFunction which we created earlier
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7703b507af5.png)
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7703c8df974.png)
Next we want to pass Body in Request Body tag
![](https://365rack.com/wp-content/uploads/2018/08/img_5b770421c2dfc.png)
Once saved, copy URL from Logic App and call it in Postman
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77045b7aa22.png)
![](https://365rack.com/wp-content/uploads/2018/08/img_5b77048203481.png)
Now go back to your Logic App and you will see that this has created a new record in Dynamics
![](https://365rack.com/wp-content/uploads/2018/08/img_5b7704c9f3f41.png)
Hope this helps.