Anchor to section titled 'undefined'

discountRedeemCodeBulkAdd
mutation

Requires Apps must have write_discounts access scope.

Asynchronously add discount redeem codes in bulk. Specify the codes to add and the discount code ID that the codes will belong to.


The list of codes that will be added to the code discount. Maximum 100 codes permitted.

Anchor to discountId
discountId
required

The ID of the code discount that the codes will be added to.


Was this section helpful?

The ID of the discount redeem code bulk creation operation. The properties and status of the operation can be tracked using the DiscountRedeemCodeBulkCreation query.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
  discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
    bulkCreation {
      id
    }
    userErrors {
      code
      field
      message
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) { discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) { bulkCreation { id } userErrors { code field message } } }",
 "variables": {
    "discountId": "gid://shopify/DiscountCodeNode/2429471",
    "codes": [
      {
        "code": "DISCOUNT_1"
      },
      {
        "code": "DISCOUNT_2"
      },
      {
        "code": "DISCOUNT_3"
      }
    ]
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
    discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
      bulkCreation {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }`,
  {
    variables: {
      "discountId": "gid://shopify/DiscountCodeNode/2429471",
      "codes": [
        {
          "code": "DISCOUNT_1"
        },
        {
          "code": "DISCOUNT_2"
        },
        {
          "code": "DISCOUNT_3"
        }
      ]
    },
  },
);

const data = await response.json();
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 discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
    discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
      bulkCreation {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }
QUERY

variables = {
  "discountId": "gid://shopify/DiscountCodeNode/2429471",
  "codes": [{"code"=>"DISCOUNT_1"}, {"code"=>"DISCOUNT_2"}, {"code"=>"DISCOUNT_3"}]
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
      discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
        bulkCreation {
          id
        }
        userErrors {
          code
          field
          message
        }
      }
    }`,
    "variables": {
      "discountId": "gid://shopify/DiscountCodeNode/2429471",
      "codes": [
        {
          "code": "DISCOUNT_1"
        },
        {
          "code": "DISCOUNT_2"
        },
        {
          "code": "DISCOUNT_3"
        }
      ]
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation discountRedeemCodeBulkAdd($discountId: ID!, $codes: [DiscountRedeemCodeInput!]!) {
    discountRedeemCodeBulkAdd(discountId: $discountId, codes: $codes) {
      bulkCreation {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "discountId" => "gid://shopify/DiscountCodeNode/2429471",
  "codes" => [{"code"=>"DISCOUNT_1"}, {"code"=>"DISCOUNT_2"}, {"code"=>"DISCOUNT_3"}],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "discountId": "gid://shopify/DiscountCodeNode/2429471",
  "codes": [
    {
      "code": "DISCOUNT_1"
    },
    {
      "code": "DISCOUNT_2"
    },
    {
      "code": "DISCOUNT_3"
    }
  ]
}
Hide code
Response
JSON
{
  "discountRedeemCodeBulkAdd": {
    "bulkCreation": {
      "id": "gid://shopify/DiscountRedeemCodeBulkCreation/989355119"
    },
    "userErrors": []
  }
}