Skip to content
Last updated

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 がインストールされていること。
  • Shopifyとその認証情報に関する基本的な知識があること。

制限事項

クエリ結果は、リソースタイプに応じて必要なカラム(名前とデータ型)と一致する必要があります。

ActionResourceColumn requireQueryNote
Update[metafield_id: Integer, value: any]SELECT metafield_id, value FROM table
CreateShop[key: String, namespace: String, value: any]SELECT key, namespace, value FROM table
CreateProduct[product_id: Integer, key: String, namespace: String, value: any]SELECT product_id, key, namespace, value FROM table ORDER BY product_idパフォーマンスを向上させるためにORDER BYを使用してください
CreateProduct Variant[variant_id: Integer, key: String, namespace: String, value: any]SELECT variant_id, key, namespace, value FROM table ORDER BY variant_idパフォーマンスを向上させるためにORDER BYを使用してください
CreateProduct 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を使用してください
CreateCustom 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を使用してください
CreateSmart 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を使用してください
CreateCustomer[customer_id: Integer, key: String, namespace: String, value: any]SELECT customer_id, key, namespace, value FROM table ORDER BY customer_idパフォーマンスを向上させるためにORDER BYを使用してください
CreateOrder[order_id: Integer, key: String, namespace: String, value: any]SELECT order_id, key, namespace, value FROM table ORDER BY order_idパフォーマンスを向上させるためにORDER BYを使用してください
CreateDraft 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を使用してください
CreateBlog[blog_id: Integer, key: String, namespace: String, value: any]SELECT blog_id, key, namespace, value FROM table ORDER BY blog_idパフォーマンスを向上させるためにORDER BYを使用してください
CreateArticle[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を使用してください
CreatePage[page_id: Integer, key: String, namespace: String, value: any]SELECT page_id, key, namespace, value FROM table ORDER BY page_idパフォーマンスを向上させるためにORDER BYを使用してください

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

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

td query --database your_database
--result configuration query

次の表は、設定キーとその説明を示しています。

Config KeyTypeRequiredDescription

Treasure Data Toolbeltのインストール

ターミナルを開き、次のコマンドを実行して最新のTreasure Data Toolbeltをインストールします。

設定キーと説明は次のとおりです。

Config Key Type Required Description
typestringyesshopify_metafield
api_keystringYesShopify APIキー。
passwordstringYesShopifyパスワード。
store_namestringYesShopifyのストア名

action

string

Yes

次の値のみを受け付けます: create または update

  • create: リソースの新しいmetafieldを作成します
  • update: 既存のmetafieldの値を更新します
resourcestringYes (action: createの場合)次の値のみを受け付けます:
  • shop
  • product
  • product_variant
  • product_image
  • custom_collection
  • smart_collection
  • customer
  • order
  • draft_order
  • blog
  • article
  • page
stop_on_failed_recordbooleanNoチェックした場合、エラーレコードが発生するとエクスポートジョブが終了します。チェックしない場合、metafieldの作成/更新が失敗してもエクスポートジョブは続行されます。

使用例

Shopのメタフィールドを作成する

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のメタフィールドを作成する

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のメタフィールドを作成する

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のメタフィールドを作成する

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"

カスタムコレクションのメタフィールドを作成する

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"

スマートコレクションのメタフィールドを作成する

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"

顧客のメタフィールドを作成する

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"

注文のメタフィールドを作成する

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"

下書き注文のメタフィールドを作成する

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"

ブログのメタフィールドを作成する

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"

記事のメタフィールドを作成する

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"

ページのメタフィールドを作成する

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"

メタフィールドを更新する

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"