# 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](/tools/cli-and-sdks/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

| **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 | Please use ORDER BY to increase performance |
| Create | Product Variant | [variant_id: Integer, key: String, namespace: String, value: any] | SELECT variant_id, key, namespace, value FROM table ORDER BY variant_id | Please use ORDER BY to increase performance |
| 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 | Please use ORDER BY to increase performance |
| 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 | Please use ORDER BY to increase performance |
| 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 | Please use ORDER BY to increase performance |
| Create | Customer | [customer_id: Integer, key: String, namespace: String, value: any] | SELECT customer_id, key, namespace, value FROM table ORDER BY customer_id | Please use ORDER BY to increase performance |
| Create | Order | [order_id: Integer, key: String, namespace: String, value: any] | SELECT order_id, key, namespace, value FROM table ORDER BY order_id | Please use ORDER BY to increase performance |
| 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 | Please use ORDER BY to increase performance |
| Create | Blog | [blog_id: Integer, key: String, namespace: String, value: any] | SELECT blog_id, key, namespace, value FROM table ORDER BY blog_id | Please use ORDER BY to increase performance |
| 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 | Please use ORDER BY to increase performance |
| Create | Page | [page_id: Integer, key: String, namespace: String, value: any] | SELECT page_id, key, namespace, value FROM table ORDER BY page_id | Please use ORDER BY to increase performance |


## Using the Command Line to Create Your Connection

You can use the CLI to configure your connection.


```bash
td query --database your_database 
--result configuration query
```

The following table identifies the configuration keys with descriptions.

| **Config Key** | **Type** | **Required** | **Description** |
|  --- | --- | --- | --- |


## Install the Treasure Data Toolbelt

Open a terminal and run the following command to install the newest [Treasure Data Toolbelt](https://toolbelt.treasuredata.com/).

Configuration keys and descriptions are as follows:

| Config Key  | Type  | Required  | Description  |
|  --- | --- | --- | --- |
| `type` | string | yes | `shopify_metafield` |
| `api_key` | string | Yes | Shopify API Key. |
| `password` | string | Yes | Shopify password. |
| `store_name` | string | Yes | Your Store Name from Shopify |
| `action`
 | string
 | Yes
 | Only accept: create or update
- create: create new metafield for resource
- update: update value of exist metafield

 |
| `resource` | string | Yes (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_record | boolean | No | If 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


```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"
```

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

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

### Create a Metafield for Product Image


```bash
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


```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"
```

### Create a Metafield for Smart Collection


```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"
```

### Create a Metafield for Customer


```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"
```

### Create a Metafield for Order


```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"
```

### Create a Metafield for Draft Order


```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"
```

### Create a Metafield for Blog


```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"
```

### Create a Metafield for Article


```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"
```

### Create a Metafield for Page


```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"
```

### Update a Metafield


```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"
```