Unsupported query - Files API - Node.js

Hi,

While trying to use the GraphQL in Node.js for add_file_to_column in the mutation mode, I’m getting an error of Unsupported query, no matter what.

The code is exactly the same as the request in the Postman, which works properly.

Please try to advise:

const formData = new FormData();
formData.append(
         'variables[file]',
         fs.createReadStream(
                 'Path to file'
         )
);
formData.append(
         'query',
         'mutation ($file: File!) {add_file_to_column (file: $file, item_id: XXXX, column_id: "files") {id}}');
fetch('https://api.monday.com/v2/file', {
    method: 'post',
    headers: {
       'Content-Type': 'multipart/form-data',
       Authorization: MONDAY_API_KEY,
    },
    body: formData,
}) .then((res) => res.json())
.then((res) => {
     console.log(JSON.stringify(res, null, 2));
})
.catch((err) => {
     console.log(err);
});

Hey @shaharsamira ,

You might find a solution to your problem here, as @dipro suggested.

In general, the file api should be improved:

  1. It should support uploading files as part of item creation, so that notifications and automations on item creation can use the uploaded files. With the current implementation, if you want to upload files as part of item creation, you will probably want to create an item update letting people know that file uploads are in progress and when they’re done.

  2. It is non-standard, as you experienced and saw in the post I mentioned above. This will also prevent you from using mature graphql clients such as apollo.

There are other saas api’s that allow uploading files from urls and this will simply and easily solve the problem of uploading files on item creation. It will also allow api consumers to use mature file storage apis such as amazon s3, cloudionary, google cloud storage, dropbox, etc. and then pass a link to the file already uploaded or stored.

Cheers,
Ronen Babayoff
Eazyform

Thanks for the answer.

How can I update a File column using S3 URL for an example?

You’re very welcome.

Regarding your question - currently you can’t - you will have to download it and then upload it using the current api. In regards to if or when will this be possible, I believe that’s a question for @Ben or @dipro.

@rbabayoff is correct – you must upload the file from memory (not by referencing a URL).

Check out this snippet to learn how to upload a file in NodeJS from a buffer: Uploading a file the hard way

I’d also recommend upvoting this feature request if you’d like to upload a file from URL: Upload file from URL

1 Like

Thank you very much,
much appreciated.