Anchor to section titled 'undefined'

collectionReorderProducts
mutation

Requires write_products 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 Collection.sortOrder must be MANUAL. Displaced products will have their position altered in a consistent manner, with no gaps.


Anchor to id
id
required

The ID of the collection on which to reorder products.

A list of moves to perform, which will be evaluated in order. Up to 250 moves are supported, the newPosition does not have to be unique.


Was this section helpful?

The asynchronous job reordering the products.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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-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();
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)
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"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/Collection/79210309",
  "moves": {
    "id": "gid://shopify/Product/20995642",
    "newPosition": "0"
  }
}
Hide code
Response
JSON
{
  "collectionReorderProducts": {
    "job": {
      "id": "gid://shopify/Job/fe401699-4382-4a0f-b32f-28a35b06d524"
    },
    "userErrors": []
  }
}