Back Up Record Data to Azure Storage

Contents

Overview

This article introduces how to back up Kintone record data to Azure Storage (External link) using webhooks (External link) .

What is Azure Storage?

Azure Storage is a feature of Microsoft Azure. It works flexibly with Azure services, achieving integrations using triggers and bindings with minimal amount of code. It is able to store NoSQL table data blobs, queues and files.

Integration Image

When a record is added into Kintone, a webhook including the record's data is sent. Azure Functions catches the webhook, and stores the record data into Azure Table Storage.

Prepare the Kintone App

The following App template is used to create an App for integration with Azure functions: AzureFunctions integration (product DB).zip (External link)

Refer to the App Templates (External link) article in the Kintone Help site for steps to install App templates into the Kintone domain. Refer to Creating an App from a Template (External link) article for the steps to create an App from a template.

Prepare Azure Storage

The "Microsoft Azure Storage Explorer" client tool is used in this article to utilize Azure Storage. Download and install the tool from the Microsoft Azure website (External link) .

Learn how to use Azure Storage Explorer with Get started with Storage Explorer (External link) .

Prepare Azure Functions

Create an Azure Function

Create the settings with reference to the Create your first function in the Azure Portal (External link) article on the Microsoft Azure website.

Bind settings

Once the function is created, choose "New Output".

Choose "Azure Table Storage".

For the "Table name", input a name that matches the table name in Azure Storage.

Check that the same name is used in Azure Storage.

Once the Azure Table Storage configuration has finished, delete the default HTTP output settings on Azure Functions.

If there is only Azure Table Storage left in the settings for the output, the setup is complete.

Sample Code

index.js for Azure Functions

Prepare the following JavaScript code for Azure Functions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
module.exports = function(context, data) {
  var record = data.body.record;
  context.bindings.outputTable = [{
    'RowKey': record.$id.value,
    'PartitionKey': record.category.value,
    'id': record.productID.value,
    'name': record.name.value,
    'price': record.price.value
  }];
  context.done();
};

RowKey, PartitionKey, id, name, and price are the field names of the table where data will be sent to.

function.json for Azure Functions

Prepare the following JSON file for Azure Functions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "table",
      "name": "outputTable",
      "tableName": "outTable",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ],
  "disabled": false
}

This JSON configures the in/out settings for Azure Functions. The JSON sets HTTP Triggers as the input and the Table of Azure Storage as the output.

The values below must be reconfigured accordingly to the Azure Storage environment.

1
2
3
"name": "outputTable",
"tableName": "outTable",
"connection": "AzureWebJobsStorage",

Webhook settings for the Kintone App

For Azure Functions to receive data, webhooks need to be set up on the Kintone App.

Webhooks will be set up on the Kintone App, so that data is sent to Azure Functions when a new record is added.

First on Azure Functions, click on the "Get function URL" link for index.json.

Copy the URL displayed in the dialog.

Navigate to the Kintone domain. Follow the steps in the Kintone Help site (External link) for configuring a new webhook. Set the Events as Record is added and the Webhook Endpoint as the URL obtained in the previous step. Save the settings and Update the App. Now ever time a new record is added to the Kintone App, the App sends the record data to Azure Functions. The index.js code then processes the data.

Test the integration

Add several records into your Kintone App. The data of the records should be added into Azure Storage, as shown below.

Reference