Anchor to section titled 'undefined'

collectionDelete
mutation

Requires write_products access scope. Also: The store must not be on the Starter or Retail plans and user must have a permission to delete collection.

Deletes a collection.


The collection to delete.


Was this section helpful?

The ID of the collection that was deleted. Returns null if the collection doesn't exist.

The shop associated with the collection.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation collectionDelete($input: CollectionDeleteInput!) {
  collectionDelete(input: $input) {
    deletedCollectionId
    shop {
      id
      name
    }
    userErrors {
      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 collectionDelete($input: CollectionDeleteInput!) { collectionDelete(input: $input) { deletedCollectionId shop { id name } userErrors { field message } } }",
 "variables": {
    "input": {
      "id": "gid://shopify/Collection/1009501285"
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation collectionDelete($input: CollectionDeleteInput!) {
    collectionDelete(input: $input) {
      deletedCollectionId
      shop {
        id
        name
      }
      userErrors {
        field
        message
      }
    }
  }`,
  {
    variables: {
      "input": {
        "id": "gid://shopify/Collection/1009501285"
      }
    },
  },
);

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 collectionDelete($input: CollectionDeleteInput!) {
    collectionDelete(input: $input) {
      deletedCollectionId
      shop {
        id
        name
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

variables = {
  "input": {
    "id": "gid://shopify/Collection/1009501285"
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation collectionDelete($input: CollectionDeleteInput!) {
      collectionDelete(input: $input) {
        deletedCollectionId
        shop {
          id
          name
        }
        userErrors {
          field
          message
        }
      }
    }`,
    "variables": {
      "input": {
        "id": "gid://shopify/Collection/1009501285"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation collectionDelete($input: CollectionDeleteInput!) {
    collectionDelete(input: $input) {
      deletedCollectionId
      shop {
        id
        name
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "input" => [
    "id" => "gid://shopify/Collection/1009501285",
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "id": "gid://shopify/Collection/1009501285"
  }
}
Hide code
Response
JSON
{
  "collectionDelete": {
    "deletedCollectionId": "gid://shopify/Collection/1009501285",
    "shop": {
      "id": "gid://shopify/Shop/26371970",
      "name": "Snowdevil"
    },
    "userErrors": []
  }
}