A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hey Team,
Hoping someone can help me as I can't seem to get the GenericFile endpoint to return a list of ID's for PDF files that I have uploaded to the store.
Is it possible to return a list of file ID's for PDF files uploaded via the admin store?
Further investigation it actually seems to be falling over when it hits a PDF file.
So even returning a MediaImage request for example, it is hitting a PDF in the file list and returning an internal error.
I confirmed this by uploading a PDF, seeing a failed response and then once the pdf file was removed it returned results further then when the PDF file was uploaded.
Hi @GK-Luke 👋
The `GenericFile` implements the `File` interface rather than the `Media` interface, so the `media_type` filter in the files query wouldn't support PDFs. One workaround would be to fragment on the `GenericFile` only, and fetch only these fields similar to the below.
{
files (first:3, sortKey: CREATED_AT, reverse: true){
nodes {
... on GenericFile {
id
url
}
}
}
}
The response may include "empty" nodes to represent other file types (MediaImage/Video) but should only return the ids and urls for GenericFile types.
{
"data": {
"files": {
"nodes": [
{
"id": "gid://shopify/GenericFile/22518982738038",
"url": "https://cdn.shopify.com/s/files/.../GraphQL_Admin_API_reference.pdf?v=1671817569"
},
{}, // <--- this is an image
{} // <--- this is an image
]
}
},
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog