Discount codes guide

Add discount codes in bulk with the Shopify GraphiQL app

Make my batches

Set up GraphiQL

Install the app from https://shopify-graphiql-app.shopifycloud.com/ and tick read_discounts and write_discounts when it asks for access scopes.

The mutation

Paste this into the query box once.

Mutation
mutation AddDiscountCodes($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
  discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
    bulkCreation {
      id
    }
    userErrors {
      code
      field
      message
    }
  }
}

The variables

Paste one batch into the Variables box and press Run. The tool writes every batch for you.

Variables (one batch)
{
  "discountId": "gid://shopify/DiscountCodeNode/123456789",
  "codes": [
    {
      "code": "SPRING-7KQ4-M2XD"
    },
    {
      "code": "SPRING-9FHT-3BWN"
    }
  ]
}

Check which codes failed

Each response includes bulkCreation.id. Run this query with that ID to see how many codes were added and the error for any that weren’t.

Status query
query CheckDiscountCodeJob($id: ID!) {
  discountRedeemCodeBulkCreation(id: $id) {
    id
    done
    codesCount
    importedCount
    failedCount
    codes(first: 250) {
      nodes {
        code
        errors {
          field
          message
        }
      }
    }
  }
}

Find the discount ID

If you don’t have the ID handy, this lists your newest code discounts.

Lookup query
query FindCodeDiscounts {
  codeDiscountNodes(first: 25, reverse: true) {
    nodes {
      id
      codeDiscount {
        __typename
        ... on DiscountCodeBasic { title status }
        ... on DiscountCodeBxgy { title status }
        ... on DiscountCodeFreeShipping { title status }
        ... on DiscountCodeApp { title status }
      }
    }
  }
}

More guides

Sources: discountRedeemCodeBulkAdd, Shopify CLI store execute, Shopify Help Center: discount codes. Not affiliated with, endorsed by, or sponsored by Shopify Inc. Shopify is a trademark of Shopify Inc.