Skip to content
Last updated

Shopify Export Integration CLI

You can export data results from TD to Shopify using CLI (TD Toolbelt).

This feature is in BETA version. For more information, contact your Customer Success Representative.

Prerequisites

  • TD Toolbelt is installed.
  • Basic knowledge of Shopify and Shopify credentials.

Limitations

The query result must match require columns(name & data type) with resource type

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_idPlease use ORDER BY to increase performance
CreateProduct Variant[variant_id: Integer, key: String, namespace: String, value: any]SELECT variant_id, key, namespace, value FROM table ORDER BY variant_idPlease use ORDER BY to increase performance
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_idPlease use ORDER BY to increase performance
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_idPlease use ORDER BY to increase performance
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_idPlease use ORDER BY to increase performance
CreateCustomer[customer_id: Integer, key: String, namespace: String, value: any]SELECT customer_id, key, namespace, value FROM table ORDER BY customer_idPlease use ORDER BY to increase performance
CreateOrder[order_id: Integer, key: String, namespace: String, value: any]SELECT order_id, key, namespace, value FROM table ORDER BY order_idPlease use ORDER BY to increase performance
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_idPlease use ORDER BY to increase performance
CreateBlog[blog_id: Integer, key: String, namespace: String, value: any]SELECT blog_id, key, namespace, value FROM table ORDER BY blog_idPlease use ORDER BY to increase performance
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_idPlease use ORDER BY to increase performance
CreatePage[page_id: Integer, key: String, namespace: String, value: any]SELECT page_id, key, namespace, value FROM table ORDER BY page_idPlease use ORDER BY to increase performance

Using the Command Line to Create Your Connection

You can use the CLI to configure your connection.

td query --database your_database 
--result configuration query

The following table identifies the configuration keys with descriptions.

Config KeyTypeRequiredDescription

Install the Treasure Data Toolbelt

Open a terminal and run the following command to install the newest Treasure Data Toolbelt.

Configuration keys and descriptions are as follows:

Config Key Type Required Description
typestringyesshopify_metafield
api_keystringYesShopify API Key.
passwordstringYesShopify password.
store_namestringYesYour Store Name from Shopify

action

string

Yes

Only accept: create or update

  • create: create new metafield for resource
  • update: update value of exist metafield
resourcestringYes (for action: create)Only accept value:
  • shop
  • product
  • product_variant
  • product_image
  • custom_collection
  • smart_collection
  • customer
  • order
  • draft_order
  • blog
  • article
  • page
stop_on_failed_recordbooleanNoIf checked, export jobs will terminate if an error record occurs. If left unchecked, export jobs still proceed even if a metafield created/updated failed.

Examples

Create a Metafield for 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"

Create a Metafield for 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"

Create a Metafield for 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"

Create a Metafield for Product Image

td query \
  --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"

Create a Metafield for Custom Collection

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"

Create a Metafield for Smart Collection

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"

Create a Metafield for Customer

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"

Create a Metafield for Order

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"

Create a Metafield for Draft Order

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"

Create a Metafield for Blog

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"

Create a Metafield for Article

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"

Create a Metafield for Page

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"

Update a Metafield

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"