### Ruby Example for Creating URL Redirect Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/urlRedirectCreate A Ruby example demonstrating how to create a URL redirect using the ShopifyAPI client. It includes session setup and query execution. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation UrlRedirectCreate($urlRedirect: UrlRedirectInput!) { urlRedirectCreate(urlRedirect: $urlRedirect) { urlRedirect { id path target } userErrors { field message } } } QUERY variables = { "urlRedirect": { "path": "/thepath", "target": "/thetarget" } } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Node.js: Get Active Subscriptions for App Installation Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Node.js example using the Shopify GraphQL client to fetch active subscriptions for an app installation. Requires a configured session. ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { appInstallation(id: "gid://shopify/AppInstallation/881878037") { activeSubscriptions { id } } }`, }); ``` -------------------------------- ### Ruby Example for Blog Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/blogCreate Illustrates how to create a blog using the ShopifyAPI Ruby client. This example sets up the session, client, and executes the GraphQL mutation with variables. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation CreateBlog($blog: BlogCreateInput!) { blogCreate(blog: $blog) { blog { id title handle templateSuffix commentPolicy } userErrors { code field message } } } QUERY variables = { "blog": { "title": "New Blog Title", "handle": "new-blog-title", "templateSuffix": "standard", "commentPolicy": "MODERATED" } } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Shopify CLI Example for Price List Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/priceListCreate Shows how to use the Shopify CLI to execute the `priceListCreate` mutation with the specified query and variables. ```bash shopify app execute \ --query \ 'mutation PriceListCreate($input: PriceListCreateInput!) { priceListCreate(input: $input) { userErrors { field message } priceList { id name currency parent { adjustment { type value } } } }' \ --variables \ '{ "input": { "name": "Price List", "currency": "USD", "parent": { "adjustment": { "type": "PERCENTAGE_INCREASE", "value": 10 } } } }' ``` -------------------------------- ### cURL: Get Active Subscriptions for App Installation Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Example cURL command to query active subscriptions for an app installation. Replace placeholders with your store's domain and access token. ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2026-04/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { appInstallation(id: \"gid://shopify/AppInstallation/881878037\") { activeSubscriptions { id } } }" }' ``` -------------------------------- ### Shopify CLI Example Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeBulkDeactivate This example shows how to execute the discountCodeBulkDeactivate mutation using the Shopify CLI. It requires the --query and --variables flags. ```bash shopify app execute \ --query \ 'mutation discountCodeBulkDeactivate($search: String, $ids: [ID!]) { discountCodeBulkDeactivate(search: $search, ids: $ids) { job { id } userErrors { code field message } } }' \ --variables \ '{ "ids": [ "gid://shopify/DiscountCodeNode/1" ], "search": "discount_type:bxgy" }' ``` -------------------------------- ### Ruby: Get Active Subscriptions for App Installation Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Ruby example using the ShopifyAPI client to query active subscriptions for an app installation. Ensure session and access token are correctly configured. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { appInstallation(id: "gid://shopify/AppInstallation/881878037") { activeSubscriptions { id } } } QUERY response = client.query(query: query) ``` -------------------------------- ### Shopify CLI Example Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreateMedia Example of how to execute the `productCreateMedia` mutation using the Shopify CLI. ```APIDOC ```bash shopify app execute \ --query \ 'mutation ProductImageCreate($id: ID!) { productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: "https://path.to/image.jpg", alt: "Alt text."}]) { media { id alt status ... on MediaImage { image { url } } } mediaUserErrors { field message } } }' \ --variables \ '{ \ "id": "gid://shopify/Product/121709582" }' ``` ``` -------------------------------- ### React Router: Get Active Subscriptions for App Installation Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Loader function for React Router to fetch active subscriptions for an app installation using the Shopify Admin API. Requires authentication setup. ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { appInstallation(id: "gid://shopify/AppInstallation/881878037") { activeSubscriptions { id } } }`, ); const json = await response.json(); return json.data; ``` -------------------------------- ### Create Product using Ruby Client Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreate This Ruby example shows how to create a product using the ShopifyAPI::Clients::Graphql::Admin client. It defines the session and constructs the GraphQL query. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation { productCreate(product: {title: "Cool socks", productOptions: [{name: "Color", values: [{name: "Red"}, {name: "Blue"}]}, {name: "Size", values: [{name: "Small"}, {name: "Large"}]}]}) { product { id title options { id name position optionValues { id name hasVariants } } } userErrors { field message } } } QUERY response = client.query(query: query) ``` -------------------------------- ### Get App Installation Metafield with Ruby Client Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This Ruby example demonstrates how to query for an app installation's metafield using the ShopifyAPI GraphQL client. It requires an authenticated session and defines the query and variables separately. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query AppInstallationMetafield($namespace: String!, $key: String!, $ownerId: ID!) { appInstallation(id: $ownerId) { apiKey: metafield(namespace: $namespace, key: $key) { value } } } QUERY variables = { "namespace": "secret_keys", "key": "api_key", "ownerId": "gid://shopify/AppInstallation/1002334195" } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Get App Installation Access Scopes (Node.js) Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This Node.js example demonstrates fetching app installation access scopes using the Shopify SDK's GraphQL client. Ensure the session object is correctly initialized. ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { appInstallation(id: "gid://shopify/AppInstallation/1002334195") { accessScopes { handle description } } }`, }); ``` -------------------------------- ### Create Product with Options Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreate This example demonstrates how to create a new product with specified options like color and size using the productCreate mutation. It shows the request structure and the expected response, including product details and any user errors. ```APIDOC ## GraphQL Mutation: productCreate (with Options) ### Description Creates a new product with specified options. This mutation allows for defining product variants based on attributes like color and size. ### Method POST ### Endpoint `/admin/api/2026-04/graphql.json` ### Request Body ```json { "query": "mutation { productCreate(product: {title: \"Cool socks\", productOptions: [{name: \"Color\", values: [{name: \"Red\"}, {name: \"Blue\"}]}, {name: \"Size\", values: [{name: \"Small\"}, {name: \"Large\"}]}]}) { product { id title options { id name position optionValues { id name hasVariants } } } userErrors { field message } } }" } ``` ### Response #### Success Response (200) Returns the created product's ID, title, options, and option values. It also includes any user-generated errors. #### Response Example ```json { "productCreate": { "product": { "id": "gid://shopify/Product/1072482054", "title": "Cool socks", "options": [ { "id": "gid://shopify/ProductOption/1064577875", "name": "Color", "position": 1, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054674807", "name": "Red", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054674808", "name": "Blue", "hasVariants": false } ] }, { "id": "gid://shopify/ProductOption/1064577876", "name": "Size", "position": 2, "optionValues": [ { "id": "gid://shopify/ProductOptionValue/1054674809", "name": "Small", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/1054674810", "name": "Large", "hasVariants": false } ] } ] }, "userErrors": [] } } ``` ``` -------------------------------- ### Shopify CLI Example for Product Media Deletion Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productDeleteMedia Shows how to use the Shopify CLI to execute the `productDeleteMedia` mutation with provided query and variables. ```bash shopify app execute \ --query \ 'mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) { productDeleteMedia(mediaIds: $mediaIds, productId: $productId) { deletedMediaIds deletedProductImageIds mediaUserErrors { field message } product { id title media(first: 5) { nodes { alt mediaContentType status } } } }' \ --variables \ '{ "mediaIds": [ "gid://shopify/Video/-1", "gid://shopify/Video/723685877" ], "productId": "gid://shopify/Product/108828309" }' ``` -------------------------------- ### Get App Installation Metafield with Direct API Access Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This example shows how to fetch an app installation's metafield using the Fetch API in a JavaScript environment. It sends a POST request to the GraphQL endpoint with the query and variables. ```javascript const response = await fetch('shopify:admin/api/2026-04/graphql.json', { method: 'POST', body: JSON.stringify({ query: ` query AppInstallationMetafield($namespace: String!, $key: String!, $ownerId: ID!) { appInstallation(id: $ownerId) { apiKey: metafield(namespace: $namespace, key: $key) { value } } } `, variables: { "namespace": "secret_keys", "key": "api_key", "ownerId": "gid://shopify/AppInstallation/1002334195" }, }), }); const { data } = await response.json(); console.log(data); ``` -------------------------------- ### Shopify CLI Example for Carrier Service Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/carrierServiceCreate Shows how to use the Shopify CLI to execute the CarrierServiceCreate mutation with provided query and variables. ```bash shopify app execute \ --query \ 'mutation CarrierServiceCreate($input: DeliveryCarrierServiceCreateInput!) { carrierServiceCreate(input: $input) { carrierService { id name callbackUrl active supportsServiceDiscovery } userErrors { field message } } }' \ --variables \ '{ \ "input": { "name": "test carrier service", "callbackUrl": "https://example.com/", "supportsServiceDiscovery": true, "active": true } }' ``` -------------------------------- ### Get App Installation Uninstall URL (Node.js) Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This Node.js example shows how to use the Shopify SDK's GraphQL client to fetch the uninstall URL for an app installation. Make sure the session object is correctly initialized. ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { appInstallation(id: "gid://shopify/AppInstallation/688276949") { uninstallUrl } }`, }); ``` -------------------------------- ### Shopify CLI Example Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticAppCreate This example demonstrates how to create an automatic app discount using the Shopify CLI. It includes the mutation, variables, and expected response structure. ```APIDOC ## Shopify CLI ### Description Use the Shopify CLI to create an automatic app discount. This mutation allows for detailed configuration of the discount, including its title, duration, and combinability with other discount types. ### Mutation discountAutomaticAppCreate ### Parameters #### automaticAppDiscount (DiscountAutomaticAppInput!) - **title** (string) - Required - The title of the discount. - **functionId** (uuid!) - Required - The ID of the Shopify Function to use for the discount. - **startsAt** (DateTime) - Optional - The date and time when the discount becomes active. - **endsAt** (DateTime) - Optional - The date and time when the discount expires. - **combinesWith** (DiscountCombinationsInput) - Optional - Specifies which other discount types this discount can combine with. - **orderDiscounts** (boolean) - Optional - Whether this discount can combine with order discounts. - **productDiscounts** (boolean) - Optional - Whether this discount can combine with product discounts. - **shippingDiscounts** (boolean) - Optional - Whether this discount can combine with shipping discounts. - **metafields** (MetafieldsInput) - Optional - Metafields to configure the associated Shopify Function. - **namespace** (String!) - Required - The namespace for the metafield. - **key** (String!) - Required - The key for the metafield. - **type** (String!) - Required - The type of the metafield. - **value** (String!) - Required - The value of the metafield, often in JSON format for function configuration. ### Request Example ```bash shopify app execute \ --query \ 'mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {\n discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {\n userErrors {\n field\n message\n }\n automaticAppDiscount {\n discountId\n title\n startsAt\n endsAt\n status\n appDiscountType {\n appKey\n functionId\n }\n combinesWith {\n orderDiscounts\n productDiscounts\n shippingDiscounts\n }\n }\n }\n}' \ --variables \ '{\n "automaticAppDiscount": {\n "title": "$5 discount",\n "functionId": "a3cdef66-d84a-4254-9216-b6dd723005ad",\n "startsAt": "2025-02-02T17:09:21Z",\n "endsAt": "2025-02-02T17:09:21Z",\n "combinesWith": {\n "orderDiscounts": false,\n "productDiscounts": false,\n "shippingDiscounts": false\n },\n "metafields": [\n {\n "namespace": "default",\n "key": "function-configuration",\n "type": "json",\n "value": "{\\\"discounts\\\":[{\\\"value\\\": {\\\"fixedAmount\\\": {\\\"amount\\\": 5}}}, {\\\ ``` ```APIDOC ## Response ### Success Response (200) - **discountAutomaticAppCreate** (object) - The result of the mutation. - **userErrors** (array) - A list of errors encountered during the mutation. - **field** (string) - The field that caused the error. - **message** (string) - The error message. - **automaticAppDiscount** (object) - The created automatic app discount. - **discountId** (ID!) - The unique identifier for the discount. - **title** (string) - The title of the discount. - **startsAt** (DateTime) - The date and time the discount becomes active. - **endsAt** (DateTime) - The date and time the discount expires. - **status** (DiscountStatus!) - The current status of the discount. - **appDiscountType** (AppDiscountType) - Information about the app discount type. - **appKey** (String!) - The key of the app associated with the discount. - **functionId** (uuid!) - The ID of the Shopify Function used. - **combinesWith** (DiscountCombinations) - Specifies which other discount types this discount can combine with. - **orderDiscounts** (boolean) - Whether this discount can combine with order discounts. - **productDiscounts** (boolean) - Whether this discount can combine with product discounts. - **shippingDiscounts** (boolean) - Whether this discount can combine with shipping discounts. ### Response Example ```json { "discountAutomaticAppCreate": { "userErrors": [], "automaticAppDiscount": { "discountId": "gid://shopify/DiscountAutomaticNode/1057856655", "title": "$5 discount", "startsAt": "2025-02-02T17:09:21Z", "endsAt": "2025-02-02T17:09:21Z", "status": "EXPIRED", "appDiscountType": { "appKey": "shopify-web", "functionId": "13d358d1-2a5b-4a39-a6f9-8f53394e440d" }, "combinesWith": { "orderDiscounts": false, "productDiscounts": false, "shippingDiscounts": false } } } } ``` ``` -------------------------------- ### App Installation Metafields Response Example Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This is an example of the JSON response structure when querying for app installation metafields. ```json { "appInstallation": { "metafields": { "edges": [ { "node": { "namespace": "secret_keys", "key": "api_key", "value": "aSBhbSBhIHNlY3JldCBrZXk=" } } ] } } } ``` -------------------------------- ### Product Create with SEO and Tags Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreate This example demonstrates creating a product with advanced settings including SEO information, product type, vendor, status, handle, and tags. ```APIDOC ## productCreate (Mutation) ### Description Creates a new product with comprehensive details including title, description, type, vendor, status, handle, SEO settings, tags, and product options. ### Method `productCreate` ### Parameters - `product` (object) - Required - The product data to create. - `title` (String) - Required - The title of the product. - `descriptionHtml` (String) - Optional - The HTML description of the product. - `productType` (String) - Optional - The type of the product. - `vendor` (String) - Optional - The vendor of the product. - `status` (ProductStatus) - Optional - The status of the product (e.g., 'ACTIVE'). - `handle` (String) - Optional - The handle for the product URL. - `seo` (SeoInput) - Optional - SEO settings for the product. - `title` (String) - Required - The SEO title. - `description` (String) - Required - The SEO description. - `tags` (Array of String) - Optional - Tags associated with the product. - `productOptions` (Array of ProductOptionInput) - Optional - Configurable options for the product. - `name` (String) - Required - The name of the option (e.g., 'Size'). - `values` (Array of ProductOptionValueInput) - Required - The values for the option. - `name` (String) - Required - The name of the option value (e.g., '16oz'). ### Response #### Success Response Returns the created product's ID, title, handle, description, type, vendor, status, SEO details, tags, options, and variants. - `product` (Product) - The created product object. - `id` (ID) - The unique identifier for the product. - `title` (String) - The title of the product. - `handle` (String) - The handle of the product. - `descriptionHtml` (String) - The HTML description of the product. - `productType` (String) - The type of the product. - `vendor` (String) - The vendor of the product. - `status` (ProductStatus) - The status of the product. - `seo` (Seo) - SEO information for the product. - `title` (String) - The SEO title. - `description` (String) - The SEO description. - `tags` (Array of String) - Tags associated with the product. - `options` (Array of ProductOption) - Product options. - `id` (ID) - The unique identifier for the option. - `name` (String) - The name of the option. - `position` (Int) - The position of the option. - `values` (Array of String) - The values for the option. - `optionValues` (Array of ProductOptionValue) - Detailed option values. - `id` (ID) - The unique identifier for the option value. - `name` (String) - The name of the option value. - `hasVariants` (Boolean) - Indicates if this option value creates variants. - `variants` (ProductVariantConnection) - A connection to the product's variants. - `nodes` (Array of ProductVariant) - A list of product variant nodes. - `id` (ID) - The unique identifier for the variant. - `title` (String) - The title of the variant. - `selectedOptions` (Array of SelectedOption) - The selected options for this variant. - `name` (String) - The name of the option. - `value` (String) - The value of the option. - `userErrors` (Array of UserError) - A list of errors encountered during the mutation. - `field` (String) - The field that caused the error. - `message` (String) - The error message. ### Request Example ```graphql mutation { productCreate(product: {title: "Eco-Friendly Water Bottle", descriptionHtml: "

Stay hydrated with our premium stainless steel water bottle. Features double-wall insulation to keep drinks cold for 24 hours or hot for 12 hours.

", productType: "Drinkware", vendor: "EcoLifestyle", status: ACTIVE, handle: "eco-friendly-water-bottle", seo: {title: "Eco Water Bottle - 24hr Cold, 12hr Hot | EcoLifestyle", description: "Premium stainless steel water bottle with double-wall insulation. Eco-friendly, BPA-free, and perfect for active lifestyles. Free shipping available."}, tags: ["eco-friendly", "stainless-steel", "insulated", "BPA-free", "sports", "outdoors"], productOptions: [{name: "Size", values: [{name: "16oz"}, {name: "20oz"}, {name: "32oz"}]}, {name: "Color", values: [{name: "Forest Green"}, {name: "Ocean Blue"}, {name: "Sunset Orange"}]}]}) { product { id title handle descriptionHtml productType vendor status seo { title description } tags options { id name position values optionValues { id name hasVariants } } variants(first: 1) { nodes { id title selectedOptions { name value } } } } userErrors { field message } } } ``` ``` -------------------------------- ### Create a Buy X Get Y Discount Code Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeBxgyCreate Use the `discountCodeBxgyCreate` mutation to create a Buy X Get Y discount code. This example demonstrates setting up a discount where customers buy 3 items from a specific collection and get 2 items from the same collection at a 20% discount. It also shows how to set start and end dates, customer segments, and usage limits. ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) { discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) { codeDiscountNode { codeDiscount { ... on DiscountCodeBxgy { title codes(first: 10) { nodes { code } } startsAt endsAt customerBuys { items { ...collectionsFragment } value { ... on DiscountQuantity { quantity } } } customerGets { value { ... on DiscountOnQuantity { effect { ... on DiscountPercentage { percentage } } quantity { quantity } } } items { ...collectionsFragment } } context { ... on DiscountCustomerSegments { segments { id } } } appliesOncePerCustomer } } } userErrors { field code message } } } fragment collectionsFragment on DiscountCollections { collections(first: 10) { nodes { id title } } }`, { variables: { "bxgyCodeDiscount": { "code": "SUMMERSALE", "title": "SUMMERSALE", "customerBuys": { "items": { "collections": { "add": [ "gid://shopify/Collection/1007901140" ] } }, "value": { "quantity": "3" } }, "customerGets": { "items": { "collections": { "add": [ "gid://shopify/Collection/1007901140" ] } }, "value": { "discountOnQuantity": { "effect": { "percentage": 0.2 }, "quantity": "2" } } }, "context": { "customerSegments": { "add": [ "gid://shopify/Segment/210588551" ] } }, "endsAt": "2026-05-04T02:46:03-04:00", "startsAt": "2026-04-29T02:46:03-04:00", "usesPerOrderLimit": 3 } }, }, ); const json = await response.json(); return json.data; } ``` -------------------------------- ### Ruby Implementation for Product Media Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreateMedia Provides a Ruby example using the ShopifyAPI client to perform the productCreateMedia mutation. This includes setting up the session, client, and passing the query with variables. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } } QUERY variables = { "media": [ { "alt": "Image", "mediaContentType": "EXTERNAL_VIDEO", "originalSource": "https://youtu.be/32mGBDk3LSo" }, { "alt": "Image", "mediaContentType": "IMAGE", "originalSource": "invalid_img" } ], "productId": "gid://shopify/Product/121709582" } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Get Shopify Payments Balance in React Server Components Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/shopifyPaymentsAccount Example loader function using `authenticate.admin` to fetch Shopify Payments balance within a React application's server components. Requires authentication setup. ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query ShopifyPaymentsShowBalance { shopifyPaymentsAccount { balance { amount currencyCode } } }`, ); const json = await response.json(); return json.data; } ``` -------------------------------- ### Ruby Example for File Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/fileCreate Provides a Ruby example for executing the fileCreate mutation using the ShopifyAPI client. It demonstrates setting up the session, client, query, and variables for the API call. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation fileCreate($files: [FileCreateInput!]!) { fileCreate(files: $files) { files { id fileStatus alt createdAt ... on MediaImage { image { width height } } } userErrors { field message } } } QUERY variables = { "files": [ { "alt": "Laptop computer on modern desk setup", "contentType": "IMAGE", "originalSource": "https://burst.shopifycdn.com/photos/laptop-on-desk.jpg" }, { "alt": "Close-up view of laptop keyboard and screen", "contentType": "IMAGE", "originalSource": "https://burst.shopifycdn.com/photos/laptop- closeup.jpg" } ] } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Get Draft Order by ID using React Router Loader Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/draftOrder This example demonstrates how to fetch a draft order within a React Router loader function using the Shopify Admin API. It requires authentication setup. ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { draftOrder(id: "gid://shopify/DraftOrder/276395349") { name } }`, ); const json = await response.json(); return json.data; } ``` -------------------------------- ### App Installation Launch URL Response Example Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Example JSON response when querying for an app installation's launch URL. ```json { "appInstallation": { "launchUrl": "https://snowdevil.myshopify.com/admin/api_permissions/1002334195/redirect" } } ``` -------------------------------- ### cURL Example for Blog Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/blogCreate Demonstrates how to execute the `blogCreate` mutation using cURL. Ensure you replace `{access_token}` and `your-development-store.myshopify.com` with your actual credentials. ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2026-04/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ \ "query": "mutation CreateBlog($blog: BlogCreateInput!) { blogCreate(blog: $blog) { blog { id title handle templateSuffix commentPolicy } userErrors { code field message } } }", "variables": { "blog": { "title": "New Blog Title", "handle": "new-blog-title", "templateSuffix": "standard", "commentPolicy": "MODERATED" } } }' ``` -------------------------------- ### Current App Installation Response Example Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/currentAppInstallation This is an example of the JSON response you can expect when querying for the current app installation. It lists the handles of the granted access scopes. ```json { "currentAppInstallation": { "accessScopes": [ { "handle": "read_all_orders" }, { "handle": "read_all_subscription_contracts" }, { "handle": "read_analytics_overviews" }, { "handle": "read_billing" }, { "handle": "read_checkouts" }, { "handle": "read_discovery" }, { "handle": "read_discovery_synonym_groups" }, { "handle": "read_payment_settings" }, { "handle": "read_subscription_plans" }, { "handle": "read_users" }, { "handle": "read_customer_merge" } ] } } ``` -------------------------------- ### Shopify CLI Example Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productVariantsBulkCreate Example of using the Shopify CLI to create product variants in bulk. ```APIDOC ## Shopify CLI ``` shopify app execute \ --query \ 'mutation CreateProductVariantsInBulkWithExistingMedia($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n productVariantsBulkCreate(productId: $productId, variants: $variants) {\n product {\n id\n }\n productVariants {\n id\n title\n media(first: 10) {\n nodes {\n id\n alt\n mediaContentType\n preview {\n status\n }\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}' \ --variables \ '{\n "productId": "gid://shopify/Product/20995642",\n "variants": [\n {\n "optionValues": [\n {\n "name": "one",\n "optionName": "Title"\n }\n ],\n "mediaId": "gid://shopify/MediaImage/730211239"\n },\n {\n "optionValues": [\n {\n "name": "two",\n "optionName": "Title"\n }\n ]\n }\n ]\n}' ``` ``` -------------------------------- ### Ruby Example for Price List Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/priceListCreate Illustrates how to perform the `priceListCreate` mutation using the ShopifyAPI client in Ruby, including session setup and query execution. ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation PriceListCreate($input: PriceListCreateInput!) { priceListCreate(input: $input) { userErrors { field message } priceList { id name currency parent { adjustment { type value } } } } } QUERY variables = { "input": { "name": "Price List", "currency": "USD", "parent": { "adjustment": { "type": "PERCENTAGE_INCREASE", "value": 10 } } } } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Example Response for App Installation Credits Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation This is an example of the JSON response structure when querying app installation credits. The 'edges' array will contain credit details if available. ```json { "appInstallation": { "credits": { "edges": [] } } } ``` -------------------------------- ### App Installation Uninstall URL Response Example Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Example JSON response when querying for an app installation's uninstall URL. The URL may be null if not applicable. ```json { "appInstallation": { "uninstallUrl": null } } ``` -------------------------------- ### Ruby Example for Catalog Creation Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/catalogCreate Provides a Ruby example for creating a catalog using the ShopifyAPI client. This includes setting up the session and defining the query and variables. ```ruby session = ShopifyAPI::Auth::Session.new ( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new ( session: session ) query = <<~QUERY mutation catalogCreate($input: CatalogCreateInput!) { catalogCreate(input: $input) { catalog { id status title publication { id autoPublish } priceList { id currency } } userErrors { field message } } } QUERY variables = { "input": { "title": "Market Catalog", "status": "ACTIVE", "context": { "marketIds": [ "gid://shopify/Market/128989799" ] }, "priceListId": "gid://shopify/PriceList/294167858", "publicationId": "gid://shopify/Publication/1056839876" } } response = client.query(query: query, variables: variables) ``` -------------------------------- ### Update Marketing Activity with UTM Parameters in React Router Loader Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/marketingActivityUpdateExternal Implement a loader function within a React Router setup to update an external marketing activity, including UTM parameters. This example uses `authenticate.admin` to get an authenticated GraphQL client. ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation marketingActivityUpdateExternal($utm: UTMInput!, $updateInput: MarketingActivityUpdateExternalInput!) { marketingActivityUpdateExternal(utm: $utm, input: $updateInput) { marketingActivity { id title marketingEvent { manageUrl previewUrl } } } }`, { variables: { "utm": { "source": "email", "medium": "newsletter", "campaign": "external-event-campaign" }, "updateInput": { "title": "New Title", "remoteUrl": "https://example.com", "remotePreviewImageUrl": "https://example.com" } }, }, ); const json = await response.json(); return json.data; } ``` -------------------------------- ### Ruby Example Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreateMedia Example of how to use the `productCreateMedia` mutation with the ShopifyAPI Ruby client. ```APIDOC ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY mutation ProductImageCreate($id: ID!) { productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: "https://path.to/image.jpg", alt: "Alt text."}]) { media { id alt status ... on MediaImage { image { url } } } mediaUserErrors { field message } } } QUERY variables = { "id": "gid://shopify/Product/121709582" } response = client.query(query: query, variables: variables) ``` ``` -------------------------------- ### Get App Installation Credits Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Retrieves a list of application credits for a given app installation. ```APIDOC ## Get App Installation Credits ### Description Retrieves a list of application credits for a given app installation. ### Query ```graphql query GetAppInstallationCredits($appInstallationId: ID!) { appInstallation(id: $appInstallationId) { credits(first: 10) { edges { node { amount { amount currencyCode } createdAt description id } } } } } ``` ### Variables ```json { "appInstallationId": "gid://shopify/AppInstallation/236444539" } ``` ``` -------------------------------- ### Node.js: Create Product Media Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/productCreateMedia This Node.js example demonstrates how to use the GraphQL client to create media for a product. It requires a configured Shopify session. ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } }`, "variables": { "media": { "alt": "Image", "mediaContentType": "IMAGE", "originalSource": "invalid_img" }, "productId": "gid://shopify/Product/121709582" }, }, }); ``` -------------------------------- ### Get App Installation ID Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Retrieves the ID of the app associated with a given app installation. ```APIDOC ## Get App Installation ID ### Description Retrieves the ID of the app associated with a given app installation. ### Query ```graphql query { appInstallation(id: "gid://shopify/AppInstallation/1002334195") { app { id } } } ``` ### Response Example ```json { "appInstallation": { "app": { "id": "gid://shopify/App/1002334195" } } } ``` ``` -------------------------------- ### Shopify CLI example for SubscriptionBillingCycleBulkCharge Source: https://shopify.dev/docs/api/admin-graphql/latest/mutations/subscriptionBillingCycleBulkCharge This example shows how to use the Shopify CLI to execute the SubscriptionBillingCycleBulkCharge mutation. It takes the query and variables as arguments. ```bash shopify app execute \ --query \ 'mutation($startDate: DateTime!, $endDate: DateTime!) { subscriptionBillingCycleBulkCharge(billingAttemptExpectedDateRange: {startDate: $startDate, endDate: $endDate}) { job { id } } }' \ --variables \ '{ "startDate": "2023-02-01T00:00:00-05:00", "endDate": "2023-02-02T23:59:59-05:00" }' ``` -------------------------------- ### Response: Active Subscriptions for App Installation Source: https://shopify.dev/docs/api/admin-graphql/latest/queries/appInstallation Example JSON response structure for active subscriptions of an app installation. ```json { "appInstallation": { "activeSubscriptions": [ { "id": "gid://shopify/AppSubscription/1029266946" } ] } } ```