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.

Image: When a record is added into the Kintone App, a webhook is send to Azure Functions, which stores the 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”.

Screenshot: User navigates on Azure Functions to 'New Output'.

Choose “Azure Table Storage”.

Screenshot: User navigates on Azure Functions to 'Azure Table Storage'.

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

Screenshot: User inputs a name for the 'Table name' field in Azure Functions.

Check that the same name is used in Azure Storage.

Screenshot: User checks that the table created in Azure Storage has the same name as the table named in Azure Functions.

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

Screenshot: User navigates on Azure Functions to delete the default HTTP output settings.

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

Screenshot: User navigates on  Azure Functions to check that only Azure Table Storage is left in the settings for the output.

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();
};

Screenshot: The sample code is entered in to Azure functions.

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
}

Screen: The sample JSON is entered in to Azure functions..

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.

Screenshot: User navigates on Azure Functions to index.json and clicks on 'Get function URL'.

Copy the URL displayed in the dialog.

Screenshot: The Get function URL key is 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.

Screenshot: The data of the Kintone records is added into Azure Storage.

Reference