Error in executing GraphQL File API

I am trying to execute File query (in GraphQL using Graphql app explorer) but I am getting internal server error.

Query:

{
{
      files(first:1) {
          edges {
              node {
                ... on MediaImage {
                  image {
                    id
                    url
                  }
                }
              }
            }
      }
    }
}

Output:

{
"errors": [
{
"message": "Internal error. Looks like something went wrong on our end.\nRequest ID: 36566f20-459c-4e9d-b577-e8aa5c592a0c (include this in support requests).",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"requestId": "36566f20-459c-4e9d-b577-e8aa5c592a0c"
}
}
]
}

And the most weird thing is this query is working on another store. I have checked all the permissions and already given read_file,write_file, read_theme,write_theme permissions.

Please help me !!

Hi lokeshgarg,

Thanks for your post. When looking up that request ID we find that the request was made through the Shopify GraphiQL App and that the problem was a permission issue due to hitting a GenericFile type object in the query result and not having the read_files permission.

It’s not currently possible to request the read_files permission through the Shopify GraphiQL App but we’ll suggest having that added in. We’ll also look into submitting a report about the internal server error coming through in this type of situation and request a clearer message about the permissions.

An example of the kind of file that would be assigned the GenericFile type are PDF and TXT files.

For now, if getting a full list of all the files is important, then it would be best to create a custom app and include the read_files permission on it and then make API calls through a tool like Postman or Insomnia.

Depending on your use case an alternate potential workaround could be to use the filename query filter to narrow down the types of files to try avoid GenericFile types, for example:

files(first: 1, query: “filename:*.jpg OR *.png OR *.gif”)

Hope you have a great day

1 Like

But still unable to download PDF and mp3 files. How can I download these extension files?

Hey @lokeshgarg - thanks for getting back in touch. Can you let us know if you’re using a custom app and still seeing the error? My understanding that if you’re using the admin-based GraphiQL app, the error will still persist. That said, if you are still using the GraphiQL app, I’m happy to pass along a note to our product team to see if they can look into this. I can’t guarantee anything, but if you can share another X-Request-ID from a recent example of the error occurring, I’d be happy to reach out on your behalf and do a little more investigation.

Hope this helps - thanks again for getting back in touch.

Al | Shopify Developer Support

Yes I am building a custom app for one of my store but I am unable to download these files extensions (PDF and mp3 files). Please see my code:

app.get('/downloadAllFiles',async (req,res) => {
  // console.log("kkk");return false;
  // use this in case of adding filters
  //files(first:100,query:"created_at:>'2023-10-21T23:39:20Z'") {
  //files(after:"graphqlID")
  //files(first: 1, query: "filename:*.jpg OR *.png OR *.gif")
    const query = `{
      files(first: 100, query: "filename:*.jpg OR *.png OR *.gif") {
          edges {
              node {
                ... on MediaImage {
                  image {
                    id
                    url
                  }
                }
              }
            }
      }
    }`;
  return new Promise(resolve => {
      shopify.graphql(query)
          .then((files) => files.files.edges.map(fileData => downloadFile((fileData.node.image.url !== "undefined") ? fileData.node.image.url : '', `${__dirname}/downloaded_files`)))
          // .then((files) => JSON.stringify(files))
          .catch((err) => console.error(err));
  });
})

Here I can download only these extension but I want to download my PDF and mp3 files also.

Please help me !!!