I am building a custom app for a client that lets me upload Google Sheet data into a Shopify Metaobject. Among all the fields I am populating, I need to attach an image to each metaobject.
Here is an example of a GraphQL mutation that I wrote to do this:
const query = `
mutation UpsertMetaobject($handle:MetaobjectHandleInput!, $metaobject: MetaobjectUpsertInput!){
metaobjectUpsert(handle: $handle, metaobject: $metaobject){
metaobject{
type
title: field(key: "title"){
value
}
qualities: field(key: "qualities"){
value
}
}
userErrors {
field
message
code
}
}
}
`;
const variables = {
"handle": {
"handle": handle,
"type": "hive_five_certification"
},
"metaobject": {
fields: [
{
"key": "title",
"value": `${title}`
},
{
"key": "icon",
"value": `gid://shopify/ImageSource/32543195857032`
},
{
"key": "qualities",
"value": `${qualities}`
}
]
}
As you can see from my mutation, there is a field with the key “icon” and I’m trying to use the gid of an image from my clien’t Shopify Store.
When I ran the query, I got this error:
message: 'Value must be a file reference string.'
After researching the Shopify API docs, I found an object type called GenericFile. I think I’m supposed to use the id from that object type since it seems like it is probably the “file reference” that the error message is talking about.
Is that true? And if it is, how can I incorporate GenericFile into the mutation I have above?
And if it is not true, what should I do?