Could someone please help me out - i can’t find it.
I’m creating products via the Admin API and would like to link/add the very same image to all of these products.
The image is uploaded already to Shopify and i do have a
gid://shopify/MediaImage/<id>
id. For me it looks like that all mutations around product and images do upload a new instance of the product. Even if i provide a url that is hosted on shopify.
How can i link/set an existing image to a product?
Hey @LetterT ! Thanks for the reply!
By reading the endpoints i don’t think there is something available at all add an existing image to a product. The productCreateMedia only has an Input with
originalSource
[String! ](https://shopify.dev/docs/api/admin-graphql/2024-04/scalars/String)required
The original source of the media object. This might be an external URL or a staged upload URL.
It will always create and upload a new media even if you provide a shopify URL.
The productUpdateMedia EP will only update existing media on a product but not allow linking an existing media to a new product.
Would you know if this is achievable via REST?
I’ll be dealing with a 500-1000 products and more and would love to avoid to upload the very same image over and over
Actually I don’t think all the mutations require an image to be uploaded. In fact I think they’re very granular - I just wish it wasn’t sooo complicated, but whatever …
but adding id to media { … }, the goal is to get the id of the media created, which we’ll call media_id (we’ll need this later), (which you have).
mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {
productCreateMedia(media: $media, productId: $productId) {
media {
mediaContentType
status
id
}
mediaUserErrors {
field
message
}
product {
id
}
}
}
Input variables:
{
"media": {
"mediaContentType": "IMAGE",
"originalSource":
Now for the **productUpdateMedia** mutation:
[https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productUpdateMedia?example=Update+a+product%27s+media+fields](https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productUpdateMedia?example=Update+a+product%27s+media+fields)
The input variables don't need any more urls or anything else to be uploaded. It *seems* that all you need is your productId and the **media_id**
Plan A:
I haven't use **productUpdateMedia** myself ... but perhaps you can then use **productUpdateMedia** with **media_id** on all those 500-1000 productIds of your choosing?
Plan B:
If Shopify doesn't like that, then how about this:
There's the **resourceUrl** from Step 1. Perhaps you can just **productCreateMedia** on all productIds. Again, there's no necessity to POST any more images because you say you're using the same image, and the **resourceUrl** is the same.
Curious to see what works ...
@stolle Have you find out a solution, im having the same issue. Using Graphql admin api, and getting duplicate images over and over in my Shopify Files Center evertime i try to link images.
1.fileCreate
2.productCreateMedia, providing the URL from the media uploaded to shopify Content files
Tried productUpdateMedia supplying mediaimageid from the images uploaded feom step 1. still no success.