Admin graphQL - Returning ID's for PDF files

Admin graphQL - Returning ID's for PDF files

GK-Luke
Shopify Partner
3 0 0

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? 

Replies 2 (2)

GK-Luke
Shopify Partner
3 0 0

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. 

 

Screen Shot 2022-12-21 at 2.33.23 pm.png

ShopifyDevSup
Shopify Staff
1453 238 508

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