# productCreateMedia - admin-graphql - MUTATION
Version: 2025-01

## Description
Creates media for a product.

### Access Scopes
`write_products` access scope. Also: The user must have a permission to create media for a product.


## Arguments
* [media](/docs/api/admin-graphql/2025-01/input-objects/CreateMediaInput): CreateMediaInput! - List of new media to be added to a product.
* [productId](/docs/api/admin-graphql/2025-01/scalars/ID): ID! - Specifies the product associated with the media.


## Returns
* [media](/docs/api/admin-graphql/2025-01/interfaces/Media): Media The newly created media.
* [mediaUserErrors](/docs/api/admin-graphql/2025-01/objects/MediaUserError): MediaUserError! The list of errors that occurred from executing the mutation.
* [product](/docs/api/admin-graphql/2025-01/objects/Product): Product The product associated with the media.
* [userErrors](/docs/api/admin-graphql/2025-01/objects/UserError): UserError! The list of errors that occurred from executing the mutation.


## Examples
### Add both valid and invalid media to an existing product
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } }\",\n \"variables\": {\n    \"media\": [\n      {\n        \"alt\": \"Image\",\n        \"mediaContentType\": \"EXTERNAL_VIDEO\",\n        \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n      },\n      {\n        \"alt\": \"Image\",\n        \"mediaContentType\": \"IMAGE\",\n        \"originalSource\": \"invalid_img\"\n      }\n    ],\n    \"productId\": \"gid://shopify/Product/121709582\"\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n      productCreateMedia(media: $media, productId: $productId) {\n        media {\n          alt\n          mediaContentType\n          status\n        }\n        mediaUserErrors {\n          field\n          message\n        }\n        product {\n          id\n          title\n        }\n      }\n    }`,\n    \"variables\": {\n      \"media\": [\n        {\n          \"alt\": \"Image\",\n          \"mediaContentType\": \"EXTERNAL_VIDEO\",\n          \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n        },\n        {\n          \"alt\": \"Image\",\n          \"mediaContentType\": \"IMAGE\",\n          \"originalSource\": \"invalid_img\"\n        }\n      ],\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"media\": [{\"alt\"=>\"Image\", \"mediaContentType\"=>\"EXTERNAL_VIDEO\", \"originalSource\"=>\"https://youtu.be/32mGBDk3LSo\"}, {\"alt\"=>\"Image\", \"mediaContentType\"=>\"IMAGE\", \"originalSource\"=>\"invalid_img\"}],\n  \"productId\": \"gid://shopify/Product/121709582\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"media\": [\n        {\n          \"alt\": \"Image\",\n          \"mediaContentType\": \"EXTERNAL_VIDEO\",\n          \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n        },\n        {\n          \"alt\": \"Image\",\n          \"mediaContentType\": \"IMAGE\",\n          \"originalSource\": \"invalid_img\"\n        }\n      ],\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n  productCreateMedia(media: $media, productId: $productId) {\n    media {\n      alt\n      mediaContentType\n      status\n    }\n    mediaUserErrors {\n      field\n      message\n    }\n    product {\n      id\n      title\n    }\n  }\n}"
#### Graphql Input
{
  "media": [
    {
      "alt": "Image",
      "mediaContentType": "EXTERNAL_VIDEO",
      "originalSource": "https://youtu.be/32mGBDk3LSo"
    },
    {
      "alt": "Image",
      "mediaContentType": "IMAGE",
      "originalSource": "invalid_img"
    }
  ],
  "productId": "gid://shopify/Product/121709582"
}
#### Graphql Response
{
  "data": {
    "productCreateMedia": {
      "media": [
        {
          "alt": "Image",
          "mediaContentType": "EXTERNAL_VIDEO",
          "status": "UPLOADED"
        }
      ],
      "mediaUserErrors": [
        {
          "field": [
            "media",
            "1",
            "originalSource"
          ],
          "message": "Image URL is invalid"
        }
      ],
      "product": {
        "id": "gid://shopify/Product/121709582",
        "title": "Boots"
      }
    }
  }
}

### Add invalid media to an existing product
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } }\",\n \"variables\": {\n    \"media\": {\n      \"alt\": \"Image\",\n      \"mediaContentType\": \"IMAGE\",\n      \"originalSource\": \"invalid_img\"\n    },\n    \"productId\": \"gid://shopify/Product/121709582\"\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n      productCreateMedia(media: $media, productId: $productId) {\n        media {\n          alt\n          mediaContentType\n          status\n        }\n        mediaUserErrors {\n          field\n          message\n        }\n        product {\n          id\n          title\n        }\n      }\n    }`,\n    \"variables\": {\n      \"media\": {\n        \"alt\": \"Image\",\n        \"mediaContentType\": \"IMAGE\",\n        \"originalSource\": \"invalid_img\"\n      },\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"media\": {\n    \"alt\": \"Image\",\n    \"mediaContentType\": \"IMAGE\",\n    \"originalSource\": \"invalid_img\"\n  },\n  \"productId\": \"gid://shopify/Product/121709582\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"media\": {\n        \"alt\": \"Image\",\n        \"mediaContentType\": \"IMAGE\",\n        \"originalSource\": \"invalid_img\"\n      },\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n  productCreateMedia(media: $media, productId: $productId) {\n    media {\n      alt\n      mediaContentType\n      status\n    }\n    mediaUserErrors {\n      field\n      message\n    }\n    product {\n      id\n      title\n    }\n  }\n}"
#### Graphql Input
{
  "media": {
    "alt": "Image",
    "mediaContentType": "IMAGE",
    "originalSource": "invalid_img"
  },
  "productId": "gid://shopify/Product/121709582"
}
#### Graphql Response
{
  "data": {
    "productCreateMedia": {
      "media": [],
      "mediaUserErrors": [
        {
          "field": [
            "media",
            "0",
            "originalSource"
          ],
          "message": "Image URL is invalid"
        }
      ],
      "product": {
        "id": "gid://shopify/Product/121709582",
        "title": "Boots"
      }
    }
  }
}

### Add new media to a non-existent product
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } }\",\n \"variables\": {\n    \"media\": {\n      \"alt\": \"Video\",\n      \"mediaContentType\": \"EXTERNAL_VIDEO\",\n      \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n    },\n    \"productId\": \"gid://shopify/Product/-1\"\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n      productCreateMedia(media: $media, productId: $productId) {\n        media {\n          alt\n          mediaContentType\n          status\n        }\n        mediaUserErrors {\n          field\n          message\n        }\n        product {\n          id\n          title\n        }\n      }\n    }`,\n    \"variables\": {\n      \"media\": {\n        \"alt\": \"Video\",\n        \"mediaContentType\": \"EXTERNAL_VIDEO\",\n        \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n      },\n      \"productId\": \"gid://shopify/Product/-1\"\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"media\": {\n    \"alt\": \"Video\",\n    \"mediaContentType\": \"EXTERNAL_VIDEO\",\n    \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n  },\n  \"productId\": \"gid://shopify/Product/-1\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"media\": {\n        \"alt\": \"Video\",\n        \"mediaContentType\": \"EXTERNAL_VIDEO\",\n        \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n      },\n      \"productId\": \"gid://shopify/Product/-1\"\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n  productCreateMedia(media: $media, productId: $productId) {\n    media {\n      alt\n      mediaContentType\n      status\n    }\n    mediaUserErrors {\n      field\n      message\n    }\n    product {\n      id\n      title\n    }\n  }\n}"
#### Graphql Input
{
  "media": {
    "alt": "Video",
    "mediaContentType": "EXTERNAL_VIDEO",
    "originalSource": "https://youtu.be/32mGBDk3LSo"
  },
  "productId": "gid://shopify/Product/-1"
}
#### Graphql Response
{
  "data": {
    "productCreateMedia": {
      "media": null,
      "mediaUserErrors": [
        {
          "field": [
            "productId"
          ],
          "message": "Product does not exist"
        }
      ],
      "product": null
    }
  }
}

### Add new media to an existing product
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { productCreateMedia(media: $media, productId: $productId) { media { alt mediaContentType status } mediaUserErrors { field message } product { id title } } }\",\n \"variables\": {\n    \"media\": {\n      \"alt\": \"Video\",\n      \"mediaContentType\": \"EXTERNAL_VIDEO\",\n      \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n    },\n    \"productId\": \"gid://shopify/Product/121709582\"\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n      productCreateMedia(media: $media, productId: $productId) {\n        media {\n          alt\n          mediaContentType\n          status\n        }\n        mediaUserErrors {\n          field\n          message\n        }\n        product {\n          id\n          title\n        }\n      }\n    }`,\n    \"variables\": {\n      \"media\": {\n        \"alt\": \"Video\",\n        \"mediaContentType\": \"EXTERNAL_VIDEO\",\n        \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n      },\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"media\": {\n    \"alt\": \"Video\",\n    \"mediaContentType\": \"EXTERNAL_VIDEO\",\n    \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n  },\n  \"productId\": \"gid://shopify/Product/121709582\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n    productCreateMedia(media: $media, productId: $productId) {\n      media {\n        alt\n        mediaContentType\n        status\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n      product {\n        id\n        title\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"media\": {\n        \"alt\": \"Video\",\n        \"mediaContentType\": \"EXTERNAL_VIDEO\",\n        \"originalSource\": \"https://youtu.be/32mGBDk3LSo\"\n      },\n      \"productId\": \"gid://shopify/Product/121709582\"\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {\n  productCreateMedia(media: $media, productId: $productId) {\n    media {\n      alt\n      mediaContentType\n      status\n    }\n    mediaUserErrors {\n      field\n      message\n    }\n    product {\n      id\n      title\n    }\n  }\n}"
#### Graphql Input
{
  "media": {
    "alt": "Video",
    "mediaContentType": "EXTERNAL_VIDEO",
    "originalSource": "https://youtu.be/32mGBDk3LSo"
  },
  "productId": "gid://shopify/Product/121709582"
}
#### Graphql Response
{
  "data": {
    "productCreateMedia": {
      "media": [
        {
          "alt": "Video",
          "mediaContentType": "EXTERNAL_VIDEO",
          "status": "UPLOADED"
        }
      ],
      "mediaUserErrors": [],
      "product": {
        "id": "gid://shopify/Product/121709582",
        "title": "Boots"
      }
    }
  }
}

### Create a new Product Image
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation ProductImageCreate($id: ID!) { productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: \\\"https://path.to/image.jpg\\\", alt: \\\"Alt text.\\\"}]) { media { id alt status ... on MediaImage { image { url } } } mediaUserErrors { field message } } }\",\n \"variables\": {\n    \"id\": \"gid://shopify/Product/121709582\"\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation ProductImageCreate($id: ID!) {\n      productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: \"https://path.to/image.jpg\", alt: \"Alt text.\"}]) {\n        media {\n          id\n          alt\n          status\n          ... on MediaImage {\n            image {\n              url\n            }\n          }\n        }\n        mediaUserErrors {\n          field\n          message\n        }\n      }\n    }`,\n    \"variables\": {\n      \"id\": \"gid://shopify/Product/121709582\"\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation ProductImageCreate($id: ID!) {\n    productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: \"https://path.to/image.jpg\", alt: \"Alt text.\"}]) {\n      media {\n        id\n        alt\n        status\n        ... on MediaImage {\n          image {\n            url\n          }\n        }\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"id\": \"gid://shopify/Product/121709582\"\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation ProductImageCreate($id: ID!) {\n    productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: \"https://path.to/image.jpg\", alt: \"Alt text.\"}]) {\n      media {\n        id\n        alt\n        status\n        ... on MediaImage {\n          image {\n            url\n          }\n        }\n      }\n      mediaUserErrors {\n        field\n        message\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"id\": \"gid://shopify/Product/121709582\"\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation ProductImageCreate($id: ID!) {\n  productCreateMedia(productId: $id, media: [{mediaContentType: IMAGE, originalSource: \"https://path.to/image.jpg\", alt: \"Alt text.\"}]) {\n    media {\n      id\n      alt\n      status\n      ... on MediaImage {\n        image {\n          url\n        }\n      }\n    }\n    mediaUserErrors {\n      field\n      message\n    }\n  }\n}"
#### Graphql Input
{
  "id": "gid://shopify/Product/121709582"
}
#### Graphql Response
{
  "data": {
    "productCreateMedia": {
      "media": [
        {
          "id": "gid://shopify/MediaImage/1072273196",
          "alt": "Alt text.",
          "status": "UPLOADED",
          "image": null
        }
      ],
      "mediaUserErrors": []
    }
  }
}