Anchor to collectionReorderProductscollection
collectionReorderProducts
mutation
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.
Anchor to Arguments
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.
Was this section helpful?
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.
Was this section helpful?
- 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
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation collectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {6 collectionReorderProducts(id: $id, moves: $moves) {7 job {8 id9 }10 userErrors {11 field12 message13 }14 }15 }`,16 {17 variables: {18 "id": "gid://shopify/Collection/79210309",19 "moves": {20 "id": "gid://shopify/Product/20995642",21 "newPosition": "0"22 }23 },24 },25);2627const data = await response.json();28
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/2024-10/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)
Input variables
JSON1{2 "id": "gid://shopify/Collection/79210309",3 "moves": {4 "id": "gid://shopify/Product/20995642",5 "newPosition": "0"6 }7}
Response
JSON1{2 "collectionReorderProducts": {3 "job": {4 "id": "gid://shopify/Job/af3cb206-d472-4a54-902b-f34df6af4eb5"5 },6 "userErrors": []7 }8}