# Zendesk Export Integration CLI

CLI（TD Toolbelt）を使用して、TDからZendesk Sunshineへデータ結果をエクスポートできます。

## 前提条件

- [TD Toolbelt](/tools/cli-and-sdks/td-toolbelt)がインストールされていること。
- Zendesk SunshineとZendeskアカウントの基本的な知識があること。


## 制限事項

クエリは、ターゲットイベントと一致する必須カラム（名前とデータ型）を含む必要があります。

## コマンドラインを使用した接続の作成

CLIを使用して接続を設定できます。

設定キーと説明は以下の通りです:

| **Config Key** | **Type** | **Required** | **Description** |
|  --- | --- | --- | --- |
| type | string | yes | zendesk |
| login_url | string | yes unless auth_method is client_credentials | ZendeskのログインURL |
| auth_method | string | yes | basic、token、oauth、またはclient_credentials |
| username | string | yes if auth_method is basic or token | Zendeskのユーザー名 |
| password | string | yes if auth_method is basic | Zendeskのパスワード |
| token | string | yes if auth_method is token | Zendeskのtoken |
| access_token | string | yes if auth_method is oauth | ZendeskのOAuth access token |
| subdomain | string | yes if auth_method is client_credentials | ZendeskのURLのサブドメイン部分（例: `https://example.zendesk.com` の場合は `example`）。login_urlの代わりに使用します |
| client_id | string | yes if auth_method is client_credentials | Zendesk OAuthクライアントのクライアントID（一意の識別子） |
| client_secret | string | yes if auth_method is client_credentials | Zendesk OAuthクライアントのクライアントシークレット |
| target | string | yes | エクスポート先のZendeskターゲット: event_profile、event_profile_id、またはevent_user_id |
| skip_invalid_records | string | no | 無効なレコードがある場合に続行する |


APIトークンは非推奨です
Zendeskは2026年10月27日以降、新しいAPIトークンの作成をブロックし、2027年4月30日には残りのすべてのAPIトークンを無効化します。新しいスケジュール実行エクスポートでは`client_credentials`を使用してください。OAuthクライアントは Zendesk の **管理センター** > **アプリと連携** > **API** > **OAuth クライアント** で作成し、`users:write` スコープを許可して、表示されたシークレットをその場でコピーしてください。Zendeskはシークレットを一度しか表示しません。操作はOAuthクライアントを作成したZendeskユーザーの操作として記録されるため、永続的なサービスアカウントの使用を推奨します。詳細は Zendesk の告知 [Announcing the removal of API tokens as an authentication method for API requests](https://support.zendesk.com/hc/en-us/articles/10851263566234-Announcing-the-removal-of-API-tokens-as-an-authentication-method-for-API-requests) を参照してください。

### 接続とクエリの例

プロファイルのイベントを作成

```bash
td query --database my_db \
         --result '{
            "type": "zendesk",
            "login_url": "https://{example}.zendesk.com",
            "auth_method": "basic",
            "password": "xxxxx",
            "username": "xxxxx",
            "target": "event_profile",
            "skip_invalid_records": false
         }'
         'SELECT profile_source, profile_type, profile_identifier_1,
          event_source, event_type, event_properties
          FROM your_table;'
```

OAuth Client Credentials を使用してプロファイルのイベントを作成

```bash
td query --database my_db \
         --result '{
            "type": "zendesk",
            "auth_method": "client_credentials",
            "subdomain": "{example}",
            "client_id": "xxxxx",
            "client_secret": "xxxxx",
            "target": "event_profile",
            "skip_invalid_records": false
         }'
         'SELECT profile_source, profile_type, profile_identifier_1,
          event_source, event_type, event_properties
          FROM your_table;'
```

プロファイルIDのイベントを作成

```bash
td query --database my_db \
         --result '{
            "type": "zendesk",
            "login_url": "https://{example}.zendesk.com",
            "auth_method": "basic",
            "password": "xxxxx",
            "username": "xxxxx",
            "target": "event_profile_id",
            "skip_invalid_records": false
         }'
         'SELECT profile_id, event_source, event_type, event_properties
          FROM your_table;'
```

ユーザーIDのイベントを作成

```bash
td query --database my_db \
         --result '{
            "type": "zendesk",
            "login_url": "https://{example}.zendesk.com",
            "auth_method": "basic",
            "password": "xxxxx",
            "username": "xxxxx",
            "target": "event_user_id",
            "skip_invalid_records": false
         }'
         'SELECT user_id, profile_source, profile_type, profile_identifier_1,
          event_source, event_type, event_properties
          FROM your_table;'
```