# Add discount codes in bulk

> Add up to 250 unique codes per call to an existing code discount with discountRedeemCodeBulkAdd, then check which codes were imported.

Page: https://lintelagency.com/resources/graphql/bulk-discount-codes

## In short

To create many unique discount codes, first create one code discount, then call discountRedeemCodeBulkAdd with its DiscountCodeNode ID and up to 250 codes per call. The codes are added in the background: poll discountRedeemCodeBulkCreation with the returned ID until done is true, then read importedCount, failedCount and each code’s errors, for example a code that already exists.

## Facts

- **API:** Admin GraphQL API
- **Operations:** discountRedeemCodeBulkAdd, discountRedeemCodeBulkCreation
- **Access scope:** write_discounts
- **Replaces (REST):** POST /admin/api/price_rules/{id}/batch.json
- **API version:** 2026-10
- **Last checked:** 2 November 2026

## How to use it

1. Create the discount once, in the admin or with a discountCode…Create mutation, and keep its DiscountCodeNode ID.
2. Generate your codes and split them into chunks of 250.
3. Send AddDiscountCodes per chunk and keep each bulkCreation ID.
4. Poll DiscountCodeImport until done is true. Codes with errors were not added; replace them and send them again.

## Code

### discount-redeem-code-bulk-add.graphql

```graphql
mutation AddDiscountCodes($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
  discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
    bulkCreation {
      id
      done
      codesCount
      importedCount
      failedCount
    }
    userErrors {
      code
      field
      message
    }
  }
}
```

### discount-redeem-code-bulk-add.variables.json

```json
{
  "discountId": "gid://shopify/DiscountCodeNode/1234567890",
  "codes": [
    {"code": "WELCOME-7KQ2"},
    {"code": "WELCOME-M3XD"},
    {"code": "WELCOME-P9TA"}
  ]
}
```

### discount-redeem-code-bulk-add.response.json

```json
{
  "data": {
    "discountRedeemCodeBulkAdd": {
      "bulkCreation": {
        "id": "gid://shopify/DiscountRedeemCodeBulkCreation/1234567890",
        "done": false,
        "codesCount": 3,
        "importedCount": 0,
        "failedCount": 0
      },
      "userErrors": []
    }
  }
}
```

### bulk-creation-status.graphql

```graphql
query DiscountCodeImport($id: ID!) {
  discountRedeemCodeBulkCreation(id: $id) {
    done
    codesCount
    importedCount
    failedCount
    codes(first: 250) {
      nodes {
        code
        discountRedeemCode {
          id
        }
        errors {
          code
          message
        }
      }
    }
  }
}
```

### bulk-creation-status.variables.json

```json
{
  "id": "gid://shopify/DiscountRedeemCodeBulkCreation/1234567890"
}
```

### bulk-creation-status.response.json

```json
{
  "data": {
    "discountRedeemCodeBulkCreation": {
      "done": true,
      "codesCount": 3,
      "importedCount": 2,
      "failedCount": 1,
      "codes": {
        "nodes": [
          {"code": "WELCOME-7KQ2", "discountRedeemCode": {"id": "gid://shopify/DiscountRedeemCode/1111111111"}, "errors": []},
          {"code": "WELCOME-M3XD", "discountRedeemCode": {"id": "gid://shopify/DiscountRedeemCode/1111111112"}, "errors": []},
          {"code": "WELCOME-P9TA", "discountRedeemCode": null, "errors": [{"code": "TAKEN", "message": "Code must be unique. Please try a different code."}]}
        ]
      }
    }
  }
}
```

## Limits and edge cases

- At most 250 codes per call. All codes share the discount’s value, dates and usage limits.
- Codes must be unique across the store; a duplicate fails on its own without stopping the others.
- The codes are added in the background. Wait until done is true before you send them to customers.

## Questions

### How do I generate unique discount codes in Shopify with the API?

Generate the codes in your code, then add them to one code discount with discountRedeemCodeBulkAdd, 250 per call.

### How many discount codes can I add at once?

Up to 250 per discountRedeemCodeBulkAdd call. Send more calls for larger batches.

### How do I know which codes failed?

Query discountRedeemCodeBulkCreation with the returned ID. failedCount gives the total, and each code’s errors explain why.

## Shopify documentation

- [discountRedeemCodeBulkAdd](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountRedeemCodeBulkAdd)
- [discountRedeemCodeBulkCreation](https://shopify.dev/docs/api/admin-graphql/latest/queries/discountRedeemCodeBulkCreation)

## Related

- [Turn on a discount Function as an automatic discount](https://lintelagency.com/resources/graphql/function-backed-automatic-discount)
- [List the customers in a segment](https://lintelagency.com/resources/graphql/customer-segment-members)

License: MIT. Free to use in your own store and in client work.
