Focusing on managing products, variants, and collections through the API.
Untill very recently, GraphQL API version 2023-10 allowed creation of products along with external images using ProductInput . Now in 2024-02 , you must use media to add images while creating a product.
The problem is older method was fetching images from external sources. Newer API does not do that .. and perhaps expects you to add a shopify hosted Image. That method is impossible for us as we have a lot of products and uploading images in separately is not an option .
So is there a way that we can supply external url of an image, hopefully in bulk , and shopify fetch those like it used to in earlier version ?
Solved! Go to the solution
This is an accepted solution.
I eventually found out that the error was in mutation code for bulk operation to create product. The variable $media was not passed , and was not used by graphQL back-end , as it was not a required variable, even though the data file correctly had the values set.
I 2024-02 Still shows external URLs are usable:
originalSource
String!
required
The original source of the media object. This might be an external URL or a staged upload URL.
Try something like this:
mutation {
productCreate(input: {
title: "Your Product Title",
media: [
{
originalSource: "https://example.com/your-image-url1.jpg",
alt: "Image description",
mediaContentType: "IMAGE"
},
{
originalSource: "https://example.com/your-image-url2.jpg",
alt: "Image description",
mediaContentType: "IMAGE"
}
]
}) {
product {
id
title
media(first: 10) {
nodes {
alt
mediaContentType
preview {
status
}
}
}
}
userErrors {
field
message
}
}
}
Thanks for your response. I have a few things to respond to :
1. My guess is that when the document says that originalSource can be an External URL, they are referring to External Video URL and not the Image. The reason I think that way is when you look at the definition of mediaContentType enums.
{
"input": {
"title": "Letters of Direction: Foreword by Evelyn Underhill",
// omitted for Brevity
},
"media": [
{
"alt": "Image of Front Page",
"mediaContentType": "IMAGE",
"originalSource": "https:\/\/picsum.photos\/200\/300"
}
]
}
{
"data": {
"productCreate": {
"product": {
"id": "gid:\/\/shopify\/Product\/xxxxxxxxxxxxxxx",
"title": "Letters of Direction: Foreword by Evelyn Underhill",
"mediaCount": 0,
"media": {
"nodes": []
}
},
"userErrors": []
}
},
"__lineNumber": 9
}
{
"garbage1": "IMAGE",
"garbage2": "https:\/\/picsum.photos\/200\/300"
}
Following worked through regular GraphQL call , [not the bulk one]
mutation {
productCreate(input: { title: "Your Product Title" }, media:[ { alt: "Image of Front Page", mediaContentType: IMAGE, originalSource: "https:\/\/picsum.photos\/200\/300.jpg" } ])
{
product { id title media(first: 10) { nodes { alt mediaContentType preview { status } } } }
userErrors { field message }
}
}
Notice mediaContentType value is not in quotes, even though the doc shows it in quotes. That wasted over a day. and I still don't know how to get the value without quotes in coming in from json as json is required in bulk createProduct
This is an accepted solution.
I eventually found out that the error was in mutation code for bulk operation to create product. The variable $media was not passed , and was not used by graphQL back-end , as it was not a required variable, even though the data file correctly had the values set.