collectionReorderProducts
Requires access scope. Also: The user must have a permission to reorder products within a collection.
Asynchronously reorders a set of products within a specified collection. Instead of returning an updated collection, this mutation returns a job, which should be polled. The must be
. Displaced products will have their position altered in a consistent manner, with no gaps.
Arguments
- •ID!required
The ID of the collection on which to reorder products.
- Anchor to movesmoves•[Move
Input!]! required A list of moves to perform, which will be evaluated in order. Up to 250 moves are supported, the
does not have to be unique.
Anchor to CollectionReorderProductsPayload returnsCollectionReorderProductsPayload returns
- •
The asynchronous job reordering the products.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
- Move a product to the top of a collection
- Move a product to the top of a sorted collection
- Updates the ordering type of products in a smart collection
- collectionReorderProducts reference
Examples
mutation collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) { collectionReorderProducts(id: $id, moves: $moves) { job { id } userErrors { field message } } }",
"variables": {
"id": "gid://shopify/Collection/79210309",
"moves": {
"id": "gid://shopify/Product/20995642",
"newPosition": "0"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
}
userErrors {
field
message
}
}
}`,
{
variables: {
"id": "gid://shopify/Collection/79210309",
"moves": {
"id": "gid://shopify/Product/20995642",
"newPosition": "0"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
}
userErrors {
field
message
}
}
}`,
"variables": {
"id": "gid://shopify/Collection/79210309",
"moves": {
"id": "gid://shopify/Product/20995642",
"newPosition": "0"
}
},
},
});
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 collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"id": "gid://shopify/Collection/79210309",
"moves": {
"id": "gid://shopify/Product/20995642",
"newPosition": "0"
}
}
response = client.query(query: query, variables: variables)