# Shopify Export Integration CLI CLIを使用してTreasure DataからShopifyにデータ結果をエクスポートできます(TD Toolbelt)。 This feature is in BETA version. For more information, contact your Customer Success Representative. ## 前提条件 - [TD Toolbelt](http://docs.treasuredata.com/display/PD/Installing+TD+Toolbelt) がインストールされていること。 - Shopifyとその認証情報に関する基本的な知識があること。 ## 制限事項 クエリ結果は、リソースタイプに応じて必要なカラム(名前とデータ型)と一致する必要があります。 | **Action** | **Resource** | **Column require** | **Query** | **Note** | | --- | --- | --- | --- | --- | | Update | | [metafield_id: Integer, value: any] | SELECT metafield_id, value FROM table | | | Create | Shop | [key: String, namespace: String, value: any] | SELECT key, namespace, value FROM table | | | Create | Product | [product_id: Integer, key: String, namespace: String, value: any] | SELECT product_id, key, namespace, value FROM table ORDER BY product_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Product Variant | [variant_id: Integer, key: String, namespace: String, value: any] | SELECT variant_id, key, namespace, value FROM table ORDER BY variant_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Product Image | [product_id: Integer, image_id: Integer, key: String, namespace: String, value: any] | SELECT product_id, image_id, key, namespace, value FROM table ORDER BY product_id, image_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Custom Collection | [custom_collection_id: Integer, key: String, namespace: String, value: any] | SELECT custom_collection_id, key, namespace, value FROM table ORDER BY custom_collection_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Smart Collection | [smart_collection_id: Integer, key: String, namespace: String, value: any] | SELECT smart_collection_id, key, namespace, value FROM table ORDER BY smart_collection_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Customer | [customer_id: Integer, key: String, namespace: String, value: any] | SELECT customer_id, key, namespace, value FROM table ORDER BY customer_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Order | [order_id: Integer, key: String, namespace: String, value: any] | SELECT order_id, key, namespace, value FROM table ORDER BY order_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Draft Order | [draft_order_id: Integer, key: String, namespace: String, value: any] | SELECT draft_order_id, key, namespace, value FROM table ORDER BY draft_order_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Blog | [blog_id: Integer, key: String, namespace: String, value: any] | SELECT blog_id, key, namespace, value FROM table ORDER BY blog_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Article | [blog_id: Integer, article_id: Integer, key: String, namespace: String, value: any] | SELECT blog_id, article_id, key, namespace, value FROM table ORDER BY blog_id, article_id | パフォーマンスを向上させるためにORDER BYを使用してください | | Create | Page | [page_id: Integer, key: String, namespace: String, value: any] | SELECT page_id, key, namespace, value FROM table ORDER BY page_id | パフォーマンスを向上させるためにORDER BYを使用してください | ## コマンドラインを使用した接続の作成 CLIを使用して接続を設定できます。 ```bash td query --database your_database --result configuration query ``` 次の表は、設定キーとその説明を示しています。 | **Config Key** | **Type** | **Required** | **Description** | | --- | --- | --- | --- | ## Treasure Data Toolbeltのインストール ターミナルを開き、次のコマンドを実行して最新の[Treasure Data Toolbelt](https://toolbelt.treasuredata.com/)をインストールします。 設定キーと説明は次のとおりです。 | Config Key | Type | Required | Description | | --- | --- | --- | --- | | `type` | string | yes | `shopify_metafield` | | `api_key` | string | Yes | Shopify APIキー。 | | `password` | string | Yes | Shopifyパスワード。 | | `store_name` | string | Yes | Shopifyのストア名 | | `action` | string | Yes | 次の値のみを受け付けます: create または update - create: リソースの新しいmetafieldを作成します - update: 既存のmetafieldの値を更新します | | `resource` | string | Yes (`action`: `create`の場合) | 次の値のみを受け付けます:- shop - product - product_variant - product_image - custom_collection - smart_collection - customer - order - draft_order - blog - article - page | | stop_on_failed_record | boolean | No | チェックした場合、エラーレコードが発生するとエクスポートジョブが終了します。チェックしない場合、metafieldの作成/更新が失敗してもエクスポートジョブは続行されます。 | ## 使用例 ### Shopのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "shop", "stop_on_failed_record": false }' \ "SELECT page_id, key, namespace, value FROM table ORDER BY page_id" ``` ### Productのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "product", "stop_on_failed_record": false }' \ "SELECT product_id, key, namespace, value FROM table ORDER BY product_id" ``` ### Product Variantのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "product_variant", "stop_on_failed_record": false }' \ "SELECT variant_id, key, namespace, value FROM table ORDER BY variant_id" ``` ### Product Imageのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "product_image", "stop_on_failed_record": false }' \ "SELECT product_id, image_id, key, namespace, value FROM table ORDER BY product_id, image_id" ``` ### カスタムコレクションのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "custom_collection", "stop_on_failed_record": false }' \ "SELECT custom_collection_id, key, namespace, value FROM table ORDER BY custom_collection_id" ``` ### スマートコレクションのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "smart_collection", "stop_on_failed_record": false }' \ "SELECT smart_collection_id, key, namespace, value FROM table ORDER BY smart_collection_id" ``` ### 顧客のメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "customer", "stop_on_failed_record": false }' \ "SELECT customer_id, key, namespace, value FROM table ORDER BY customer_id" ``` ### 注文のメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "order", "stop_on_failed_record": false }' \ "SELECT order_id, key, namespace, value FROM table ORDER BY order_id" ``` ### 下書き注文のメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "draft_order", "stop_on_failed_record": false }' \ "SELECT draft_order_id, key, namespace, value FROM table ORDER BY draft_order_id" ``` ### ブログのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "blog", "stop_on_failed_record": false }' \ "SELECT blog_id, key, namespace, value FROM table ORDER BY blog_id" ``` ### 記事のメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "article", "stop_on_failed_record": false }' \ "SELECT blog_id, article_id, key, namespace, value FROM table ORDER BY blog_id, article_id" ``` ### ページのメタフィールドを作成する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "create", "resource": "page", "stop_on_failed_record": false }' \ "SELECT page_id, key, namespace, value FROM table ORDER BY page_id" ``` ### メタフィールドを更新する ```bash td query \ --database my_db \ --result '{ "type": "shopify_metafield", "apikey": "xxxx", "password": "xxxx", "store_name": "xxxxx", "action": "update", "stop_on_failed_record": false }' \ "SELECT metafield_id, value FROM table" ```