Anchor to section titled 'undefined'

productReorderMedia
mutation

Requires write_products access scope. Also: The user must have a permission to reorder the media attached to a product.

Asynchronously reorders the media attached to a product.


Anchor to id
id
required

The ID of the product on which to reorder medias.

A list of moves to perform which will be evaluated in order.


Was this section helpful?

The asynchronous job which reorders the media.

The list of errors that occurred from executing the mutation.

The list of errors that occurred from executing the mutation. Use mediaUserErrors instead.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation productReorderMedia($id: ID!, $moves: [MoveInput!]!) {
  productReorderMedia(id: $id, moves: $moves) {
    job {
      id
    }
  }
}
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 productReorderMedia($id: ID!, $moves: [MoveInput!]!) { productReorderMedia(id: $id, moves: $moves) { job { id } } }",
 "variables": {
    "id": "gid://shopify/Product/108828309",
    "moves": [
      {
        "id": "gid://shopify/MediaImage/183532652",
        "newPosition": "2"
      },
      {
        "id": "gid://shopify/MediaImage/731367280",
        "newPosition": "3"
      }
    ]
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation productReorderMedia($id: ID!, $moves: [MoveInput!]!) {
    productReorderMedia(id: $id, moves: $moves) {
      job {
        id
      }
    }
  }`,
  {
    variables: {
      "id": "gid://shopify/Product/108828309",
      "moves": [
        {
          "id": "gid://shopify/MediaImage/183532652",
          "newPosition": "2"
        },
        {
          "id": "gid://shopify/MediaImage/731367280",
          "newPosition": "3"
        }
      ]
    },
  },
);

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 productReorderMedia($id: ID!, $moves: [MoveInput!]!) {
    productReorderMedia(id: $id, moves: $moves) {
      job {
        id
      }
    }
  }
QUERY

variables = {
  "id": "gid://shopify/Product/108828309",
  "moves": [{"id"=>"gid://shopify/MediaImage/183532652", "newPosition"=>"2"}, {"id"=>"gid://shopify/MediaImage/731367280", "newPosition"=>"3"}]
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation productReorderMedia($id: ID!, $moves: [MoveInput!]!) {
      productReorderMedia(id: $id, moves: $moves) {
        job {
          id
        }
      }
    }`,
    "variables": {
      "id": "gid://shopify/Product/108828309",
      "moves": [
        {
          "id": "gid://shopify/MediaImage/183532652",
          "newPosition": "2"
        },
        {
          "id": "gid://shopify/MediaImage/731367280",
          "newPosition": "3"
        }
      ]
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation productReorderMedia($id: ID!, $moves: [MoveInput!]!) {
    productReorderMedia(id: $id, moves: $moves) {
      job {
        id
      }
    }
  }
QUERY;

$variables = [
  "id" => "gid://shopify/Product/108828309",
  "moves" => [{"id"=>"gid://shopify/MediaImage/183532652", "newPosition"=>"2"}, {"id"=>"gid://shopify/MediaImage/731367280", "newPosition"=>"3"}],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/Product/108828309",
  "moves": [
    {
      "id": "gid://shopify/MediaImage/183532652",
      "newPosition": "2"
    },
    {
      "id": "gid://shopify/MediaImage/731367280",
      "newPosition": "3"
    }
  ]
}
Hide code
Response
JSON
{
  "productReorderMedia": {
    "job": {
      "id": "gid://shopify/Job/6dfa599a-a426-4030-8f10-6564abc465f9"
    }
  }
}