Focuses on API authentication, access scopes, and permission management.
Hi,
I use the graphql mutation fileCreate to upload files. The returned data is a list of files, and a single file has the following parameters: alt, createdAt, fileErrors, fileStatus and preview. Preview contains an "image" field, but this is null, which means there is no unique parameter I can use later on.
I need to be able to lookup the file I just uploaded at a later point to determine whether it still exists, but there is no unique identifier. I can query files on filename, but that is not unique enough, as you can e.g. upload "cat.png" several times, and then Shopify adds something to the name to make it unique. If only this new filename was returned in the fileCreate response.
As a hack I can set the file name to an id that is unique on my end, but I think there should be a less hackish solution.
Any suggestions for how I can determine whether a file I previously uploaded still exists?
Thanks,
-Louise
Hi Louise,
i am curious to know if you did find a better solution other than generating a unique file name?
The current API design seems very limited. Did anyone else find another solution to uniquely identify a newly uploaded file?
Best regards
Michael
I've found the following solution to work for finding the uploaded file:
fileCreate:
mutation fileCreate($files: [FileCreateInput!]!) {
fileCreate(files: $files) {
files {
__typename
createdAt
fileStatus
fileErrors {
code
message
details
}
... on MediaImage {
id
}
}
userErrors {
field
message
}
}
}
Important to fetch the ID on the MediaImage
Then fetching the MediaImage via ID to get the originalSrc URL:
query($id: ID!) {
node(id: $id) {
__typename
... on MediaImage {
id
status
fileStatus
fileErrors {
code
details
message
}
mediaErrors {
code
details
message
}
image {
originalSrc
transformedSrc(maxWidth: 400)
}
}
}
}
@Michael_CLift I am using this query to fetch the file URL. It is giving me error 'Access denied for mediaErrors field. Required access: `read_products` access scope.' If I give read_products scope it is working correctly. But why I need to give that access to read file url? Any idea?
@kavishatalsania i'm not sure actually, i would assume because this media is uploaded on a product.