Anchor to section titled 'undefined'

productAppendImages
mutation
deprecated

Requires write_products access scope. Also: The user must have a permission to append images to a product.

Appends images to a product. Use productCreateMedia instead.


Specifies the new images and the product that they're being added to.


Was this section helpful?

List of new images appended to the product.

The product object.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation productAppendImages($input: ProductAppendImagesInput!) {
  productAppendImages(input: $input) {
    newImages {
      id
      altText
    }
    product {
      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 productAppendImages($input: ProductAppendImagesInput!) { productAppendImages(input: $input) { newImages { id altText } product { id } userErrors { field message } } }",
 "variables": {
    "input": {
      "id": "gid://shopify/Product/108828309",
      "images": [
        {
          "altText": "Non-existent image.",
          "src": "fake"
        },
        {
          "altText": "Existing image.",
          "src": "http://example.com/rails_logo.gif"
        }
      ]
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation productAppendImages($input: ProductAppendImagesInput!) {
    productAppendImages(input: $input) {
      newImages {
        id
        altText
      }
      product {
        id
      }
      userErrors {
        field
        message
      }
    }
  }`,
  {
    variables: {
      "input": {
        "id": "gid://shopify/Product/108828309",
        "images": [
          {
            "altText": "Non-existent image.",
            "src": "fake"
          },
          {
            "altText": "Existing image.",
            "src": "http://example.com/rails_logo.gif"
          }
        ]
      }
    },
  },
);

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 productAppendImages($input: ProductAppendImagesInput!) {
    productAppendImages(input: $input) {
      newImages {
        id
        altText
      }
      product {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

variables = {
  "input": {
    "id": "gid://shopify/Product/108828309",
    "images": [{"altText"=>"Non-existent image.", "src"=>"fake"}, {"altText"=>"Existing image.", "src"=>"http://example.com/rails_logo.gif"}]
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation productAppendImages($input: ProductAppendImagesInput!) {
      productAppendImages(input: $input) {
        newImages {
          id
          altText
        }
        product {
          id
        }
        userErrors {
          field
          message
        }
      }
    }`,
    "variables": {
      "input": {
        "id": "gid://shopify/Product/108828309",
        "images": [
          {
            "altText": "Non-existent image.",
            "src": "fake"
          },
          {
            "altText": "Existing image.",
            "src": "http://example.com/rails_logo.gif"
          }
        ]
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation productAppendImages($input: ProductAppendImagesInput!) {
    productAppendImages(input: $input) {
      newImages {
        id
        altText
      }
      product {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "input" => [
    "id" => "gid://shopify/Product/108828309",
    "images" => [{"altText"=>"Non-existent image.", "src"=>"fake"}, {"altText"=>"Existing image.", "src"=>"http://example.com/rails_logo.gif"}],
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "id": "gid://shopify/Product/108828309",
    "images": [
      {
        "altText": "Non-existent image.",
        "src": "fake"
      },
      {
        "altText": "Existing image.",
        "src": "http://example.com/rails_logo.gif"
      }
    ]
  }
}
Hide code
Response
JSON
{
  "productAppendImages": {
    "newImages": [
      {
        "id": "gid://shopify/ProductImage/1001473906",
        "altText": "Existing image."
      }
    ],
    "product": {
      "id": "gid://shopify/Product/108828309"
    },
    "userErrors": [
      {
        "field": [
          "images",
          "0"
        ],
        "message": "Image URL is invalid"
      }
    ]
  }
}