How to create integration workflow for online stores with Azure Logic Apps
Every online store needs integration. Even if you don’t use the ERP system, you would need to integrate your newsletter subscribers with external marketing tools like MailChimp. You can achieve it in a few different ways, make integration on your own, purchase integration from the marketplace, or make something special on your own.
In this article, we will teach you how to integrate GrandNode, our open-source, ASP.NET Core shopping cart with Azure Logic Apps. You will learn how to update stock quantity from the file uploaded on the FTP server and how to send emails when an order appears in your store.
Prerequisite
- GrandNode
- Valid Azure subscription
- In the second example — Webhooks plugin
What is Azure Logic Apps?
Azure Logic Apps is a cloud-based platform for creating and running automated workflows that integrate your app with other services. In example GrandNode with your ERP system. With Azure Logic Apps, you can quickly develop integrations for your business scenarios.
Azure Logic Apps allows you to create a lot of tasks, below you can find only a few of them:
- schedule and email different types of notifications
- forward customers orders between different systems
- configure workflow for integrations
- update in-store data from file
Let’s start the journey and check how to improve your GrandNode store with simple Azure Logic Apps workflows.
Example 1 — Update stock quantity from the file on the FTP server
First of all, it’s time to create our Logic App. Create a new resource and in the search bar enter “Logic app”, open it and press the Create button.
Fill in the necessary fields like Logic App Name, select Region of the resource, Subscription, and Resource Group.
When you finish that press the Review + create button.
On the main page of the newly created Logic App, we should press the Logic app designer menu item.
In the search bar, we need to look for the FTP group of triggers. We should find the “When a file is added or modified” trigger.
In the first step, we need to specify where our file will be located, press the directory icon, and select desired folder. Then define how often do you want to check your file. Press the add new action button and look for FTP — Get file content action from the Actions list.
It’s time to select the desired file, in the Get file content — File field selects your file with stock quantities. When you’ve done that, press the Add new action button and select Initialize variable action.
Name it as you wish, we named it as csvStock, type is Array and in the value field, you need to enter the following line of code:
split(decodeUriComponent(replace(replace(uriComponent(body(‘Get_file_content’)),’%0D’,’’), ‘%0A’, ‘#NEWLINE#’)),’#NEWLINE#’)
In the next step, we will need to create Select from Data Operations.
In the first field, we need to add a function that will skip the first row of the file (row with headers).
skip(variables(‘csvStock’),1)
In the next field (Map) we need to add columns to our file. First — Id, it’s a product id. Name it as you wish, however, we recommend keeping the consistency in naming. In the value field please enter the following line:
split(item(),’,’)?[0]
In the second line enter the Stock name, it will be a column with stock qty, in the value field enter following code:
split(item(),’,’)?[1]
Save that step and create a new action — Parse JSON.
In the Content field select the Output.
You can generate schema by inserting the JSON from API request to the Use sample payload to generate schema.
If you don’t want to do that, below you can find the schema that was generated from the body of the Update stock API request.
{
"items": {
"properties": {
"Id": {
"type": "string"
},
"Stock": {
"type": "string"
}
},
"required": [
"Id",
"Stock"
],
"type": "object"
},
"type": "array"
}
Save that and add the last action — For each. You will find it in the Control group.
In the output field, you should select the Body field. Then add Select operation, in the From field select Body field, in the Map field add Id and Stock without values. the last action we should add an HTTP request. We will configure it as an endpoint.
Method: POST
URI: Endpoint for update stock action — but in the URL we will need to insert variable that we’ve initialized a few steps earlier.
Authorization: Bearer <enter token>
Content-Type: application/json
Body: Body of our request, Stock / WarehouseId, however, WarehouseId is an optional field.
That’s all. Save changes and run trigger. Stock in your store will be updated according to the stock quantities in the CSV file.
Example 2 — Export order from GrandNode to Azure
The first example is very simple. But it requires our Webhook plugin. You can purchase it on our official marketplace here:
First of all, it’s time to create our Logic App. Create a new resource and in the search bar enter “Logic app”, open it and press the Create button.
Fill in the necessary fields like Logic App Name, select Region of the resource, Subscription, and Resource Group.
When you finish that press the Review + create button. Open the Logic designer and create a new trigger — from the Request group — When a HTTP request is received.
In the request body JSON schema, you should generate a schema from webhook JSON code. You can get it directly from our webhook plugin. In the Send an email action, you should configure the content of the email.
When you save changes, you will get a webhook link that you should add in our Webhook plugin.