Anchor to section titled 'undefined'

discountCodeBulkDelete
mutation

Requires Apps must have write_discounts access scope.

Asynchronously delete 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 delete.

The ID of the saved search to use for filtering code discounts to delete.

The search query for filtering code discounts to delete.

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 deletes the code discounts.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

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

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

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

variables = {
  "search": "discount_type:percentage ends_at:past_week status:expired"
}

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

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

$variables = [
  "search" => "discount_type:percentage ends_at:past_week status:expired",
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "search": "discount_type:percentage ends_at:past_week status:expired"
}
Hide code
Response
JSON
{
  "discountCodeBulkDelete": {
    "job": {
      "id": "gid://shopify/Job/5c346b2e-979c-4449-ad4e-ac7a1090ecb4"
    },
    "userErrors": []
  }
}