Using the REST API, I would set product.published = false to unpublish the product. But now product.published isn’t a field under GraphQL.
What mutation do I use to “unpublish” the product now?
Using the REST API, I would set product.published = false to unpublish the product. But now product.published isn’t a field under GraphQL.
What mutation do I use to “unpublish” the product now?
Hey @lkates
Here’s the mutation:
mutation PublishableUnpublish($productId: ID!, $publicationId: ID!) {
publishableUnpublish(id: $productId, input: { publicationId: $publicationId }) {
publishable {
publishedOnPublication(publicationId: $publicationId)
}
userErrors {
field
message
}
}
}
Variables:
{
"productId": "gid://shopify/Product/108828309",
"publicationId": "gid://shopify/Publication/762454635"
}
You have to pass a publication ID, you can’t just say “unpublish everywhere” in one call. Query publications first to get the IDs of the channels you want to unpublish from (most stores have Online Store at minimum), then call publishableUnpublish once per publication, or pass multiple in the input array.
One important distinction: this hides the product from sales channels but the product itself stays in your store and keeps its status (active/draft/archived). If what you actually want is to take the product offline entirely (set status to draft or archived), that’s a different mutation, productUpdate with status: DRAFT or status: ARCHIVED. Pick based on whether you want to hide from channels (publishableUnpublish) or change the product’s overall state (productUpdate). For migrating from product.published = false, publishableUnpublish is the closer match.
Best,
Moeed
For products, the more direct option is productUnpublish - GraphQL Admin while publishableUnpublish - GraphQL Admin can do both products and collections.
You’d need to supply product id (obvious), but also publicationId which can be obtained from the product – Product - GraphQL Admin or can use a query to get all of them :
query GetPublicationIDs {
publications(first: 10) {
nodes {
id
name
}
}
}