🌻

EmbulkでZendesk Organizations のデータ全部抜く

2020/10/13に公開

Bulk Data Loader の Embulkを使って
ZendeskからOrganizationのデータをExportし、
ローカルに立てたMySQLにImportするお仕事があったので、
覚書き程度に設定を記載しておきます。

※Embulk等のインストール方法は別の記事を当たってください。

実行環境

  • Embulk v0.9.23
  • embulk-input-zendesk (0.3.9 java)
  • embulk-output-mysql (0.9.0 java)
  • mysql 5.7

config.yaml

Zendesk、MySQL の認証情報などはご利用の環境にあわせて修正してください。

config.yaml
in:
  type: zendesk
  login_url: https://example.zendesk.com
  auth_method: token
  username: yourname@example.com
  token: your_token
  target: organizations
  incremental: false
  columns:
  - {name: id, type: long}
  - {name: url, type: string}
  - {name: external_id, type: string}
  - {name: name, type: string}
  - {name: created_at, type: timestamp, format: '%Y-%m-%dT%H:%M:%S%z'}
  - {name: updated_at, type: timestamp, format: '%Y-%m-%dT%H:%M:%S%z'}
  - {name: domain_names, type: json}
  - {name: details, type: string}
  - {name: notes, type: string}
  - {name: group_id, type: long}
  - {name: shared_tickets, type: boolean}
  - {name: shared_comments, type: boolean}
  - {name: tags, type: json}
  - {name: organization_fields, type: json}
out:
  type: mysql
  host: my_host
  user: my_user
  password: my_password
  database: my_database
  table: zendesk_organizations
  mode: insert_direct

データ格納先 zendesk_organizations テーブル定義

(参考: Zendesk OrganizationのJSONフォーマット

CREATE TABLE `zendesk_organizations` (
  `id` bigint(20) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `external_id` varchar(45) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `domain_names` json DEFAULT NULL,
  `details` varchar(255) DEFAULT NULL,
  `notes` varchar(255) DEFAULT NULL,
  `group_id` bigint(20) DEFAULT NULL,
  `shared_tickets` tinyint(4) DEFAULT NULL,
  `shared_comments` tinyint(4) DEFAULT NULL,
  `tags` json DEFAULT NULL,
  `organization_fields` json DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

注意点としては、id系のカラムは、INTではなくBIGINTでないとデータが入りません。
(最初これでハマった)

実行

$ embulk run config.yaml

補足

embulk-input-zendesk の Readmeには、

NOTE This plugin don't support JSON type columns e.g. custom fields, tags, etc for now. But they will be supported soon.

とありますが、 このPRに記載されている通り
Zendeskのドキュメントで、arrayやhash型になっているフィールドは
上の設定のとおり columnstype でjson型を指定すればデータが取れます。

Discussion