Skip to main content

GraphQL Admin API in Shopify CLI

If you're developing an app using Shopify CLI, you can execute GraphQL Admin API queries and mutations using the shopify app execute command. You can also use shopify app bulk execute to execute bulk queries and mutations.

These commands use client credentials to authenticate your app against a store in your organization. Their permissions are defined by the access scopes that are available to your app. You should run app execute or app bulk execute from the root of your app directory.

To prevent accidental damage to production data, app execute and app bulk execute limit mutation execution to dev stores.



You can use app execute with the --query or --query-file flag to execute a GraphQL query. The command defaults to your last used dev store. You can override this with the --store flag.

Terminal

shopify app execute --query '{
products(first: 3) {
edges {
node {
id
title
}
}
}
}'

You can also use app execute with the --query flag to execute a GraphQL mutation. You can pass GraphQL variables as JSON using the --variables or --variable-file flag.

Terminal

shopify app execute --query \
'mutation productSet($identifier: ProductSetIdentifiers, $input: ProductSetInput!) {
productSet(identifier: $identifier, input: $input) {
product {
id
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"identifier": {
"handle": "my-cli-product"
},
"input": {
"handle": "my-cli-product",
"title": "Simple Product (Single Variant)",
"descriptionHtml": "<p>Product with a single variant, used to set price and SKU.</p>",
"status": "ACTIVE",
"productOptions": [
{
"name": "Title",
"values": [
{ "name": "Default Title" }
]
}
],
"variants": [
{
"optionValues": [
{
"optionName": "Title",
"name": "Default Title"
}
],
"price": 12.99,
"sku": "SIMPLE-001"
}
]
}
}'

You can use app bulk execute to export data with bulk operations. The query must adhere to the requirements for bulk query operations. Use the --watch flag to automatically poll the bulk operation until it's complete.

Terminal

shopify app bulk execute --watch --query '{
products {
edges {
node {
id
title
variants {
edges {
node {
id
sku
price
}
}
}
}
}
}
}'

You can use app bulk execute to import data with bulk operations. Use the --variable-file flag to provide the JSONL file for the bulk mutation, or pass the values directly using the --variables flag.

Terminal

cat <<EOF > products.jsonl
{ "input": { "title": "Sweet new snowboard 1", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 2", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 3", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 4", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 5", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 6", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 7", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 8", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 9", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 10", "productType": "Snowboard", "vendor": "JadedPixel" } }
EOF
shopify app bulk execute --watch --variable-file products.jsonl --query \
'mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
product {
id
title
variants(first: 10) {
edges {
node {
id
title
inventoryQuantity
}
}
}
}
userErrors {
message
field
}
}
}'

Anchor to Checking bulk operation statusChecking bulk operation status

The app bulk status command lists the status of recent bulk operations for your app.

Terminal

shopify app bulk status

You can use the --id flag to check the status of a specific bulk operation.

Terminal

shopify app bulk status --id 1234567890

Anchor to Canceling bulk operationsCanceling bulk operations

The app bulk cancel command cancels a running bulk operation. You must provide the operation ID using the --id flag.

Terminal

shopify app bulk cancel --id 1234567890


Was this page helpful?