Anchor to section titled 'undefined'

discountCodeBulkActivate
mutation

Requires Apps must have write_discounts access scope.

Asynchronously activate code discounts in bulk using a search query, a saved search ID, or a list of code discount IDs.


The IDs of the code discounts to activate.

The ID of the saved search.

The search query for filtering code discounts.

For more information on the list of supported fields and search syntax, refer to the CodeDiscountNodes query section.


Was this section helpful?

The asynchronous job that activates the code discounts.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation discountCodeBulkActivate($search: String) {
  discountCodeBulkActivate(search: $search) {
    job {
      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 discountCodeBulkActivate($search: String) { discountCodeBulkActivate(search: $search) { job { id } userErrors { code field message } } }",
 "variables": {
    "search": "discount_type:percentage starts_at:past_week"
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation discountCodeBulkActivate($search: String) {
    discountCodeBulkActivate(search: $search) {
      job {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }`,
  {
    variables: {
      "search": "discount_type:percentage starts_at:past_week"
    },
  },
);

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 discountCodeBulkActivate($search: String) {
    discountCodeBulkActivate(search: $search) {
      job {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }
QUERY

variables = {
  "search": "discount_type:percentage starts_at:past_week"
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation discountCodeBulkActivate($search: String) {
      discountCodeBulkActivate(search: $search) {
        job {
          id
        }
        userErrors {
          code
          field
          message
        }
      }
    }`,
    "variables": {
      "search": "discount_type:percentage starts_at:past_week"
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation discountCodeBulkActivate($search: String) {
    discountCodeBulkActivate(search: $search) {
      job {
        id
      }
      userErrors {
        code
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "search" => "discount_type:percentage starts_at:past_week",
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "search": "discount_type:percentage starts_at:past_week"
}
Hide code
Response
JSON
{
  "discountCodeBulkActivate": {
    "job": {
      "id": "gid://shopify/Job/2c09b7e9-e9b3-435a-8ab4-2c35f3eeb6b1"
    },
    "userErrors": []
  }
}