Announcement: Uploading files to monday.com has just become easier :)

New feature alert! :tophat:

I’m excited to announce that uploading files to monday.com has just become a bit simpler using our API, and even easier when using our SDK.

Now, when making direct calls to our API, you can upload files in a more GraphQL-like way. With your query you can now include query variables alongside files! This is compared to before when you’d need to use inline variables in the query.

Now, the following request to our API is possible:

const query = 

    mutation add_file($update_id:Int!, $file: File!) {

    add_file_to_update(update_id: $update_id, file: $file) {

    id

    }

    }

    ;

    const variables = {

    update_id: yourUpdateId,

    file: yourFile

    };

Here’s an example in Postman as well if you’d like to try this out:

  • Send the request as form-data;
  • Send a POST request to the special File endpoint:

https://api.monday.com/v2/file

  • Use the File type for the file;
  • You can use Text inputs for other Keys, and Auto for content-type;
  • In “variables”, you can include your Update ID, or Item + File column IDs. To add the File as a variable, you will need to add another Key to map the variable to another key. In the Map key, you declare the name of the variable, for example, “image”, and then set it as the variable.file.

And you should get a result as follows:

Always make sure to send your File upload requests with variables to the https://api.monday,com/v2/file Endpoint.

Here’s a cURL example as well:

curl --location --request POST 'https://api.monday.com/v2/file' \

--header 'Authorization: yourSuperSecretApiKey' \

--header 'Cookie: __cfduid=d0359804269ad2a2a33bc1bbbe9d6f18d1612880009' \

--form 'query="mutation add_file($file: File!, $update_id: Int!) {add_file_to_update(update_id: $update_id, file: $file) {id}}"' \

--form 'variables="{\"update_id\":920768626}"' \

--form 'map="{\"image\":\"variables.file\"}"' \

--form 'image=@"/Users/alexsavchuk/Downloads/300px-All_Right_Then,_Keep_Your_Secrets.jpg"'

What about the SDK, you might ask? This has now become easier too :slight_smile:

Developers using our SDK to make requests from View apps that are using seamless auth will now also enjoy seamless file uploads! monday.com will now translate any query into a multipart request IF it detects the request contains files. This means that if you’re adding files as variables, it will just work with zero extra code on your side :slight_smile:

If you are making a direct call from the server-side using the monday.api method, the translation will not work. Instead, we recommend constructing your own HTTP request using a library of your choice.

6 Likes

Is it only possible to upload a single file at a time or can you upload an array of files?

@ShawnBaden

Oh, that’s a good one :slight_smile:

To be transparent with you, it is not possible to upload multiple files in the same API call. You will indeed need to use multiple mutations to upload each file separately, I’m afraid. Using a for-loop can help in those cases, as you iterate through an array of files.

I hope this helps clarify!

-Alex

1 Like

@AlexSavchuk - It would be nice to have that functionality but I figured as much. Thank you Alex!

I am trying to use the URL of a file in one column, to transfer it to another column.
What would be the best way to do that?

It seems like I don’t understand how to get the file from the URL and properly attach it to the upfile variable.

Hello @Lindjacob ,
Currently, that is not possible. That is what this feature request is about so, you can upvote it to move it up the priority ladder. The only way currently is to download the file and then reupload it.

1 Like

I’m struggling to make this work. I’m trying to upload a file to Monday column using the sdk.

My code looks like this:

const response = await monday.api(`mutation add_file($file_content: File!) {
      add_file_to_column (item_id: ${itemId}, column_id: "${columnId}", file: $file_content) {
          id
      }
    }`, { variables: { file_content: fileBuffer }});

When I execute that from my app, I receive a 500 internal server error. I assume this is because the call is sent to the “/v2” endpoint with “content-type: application/json” (as opposed to the “v2/file” endpoint with the multipart content type).

I don’t see any example of this functionality using the SDK. Is there any particular thing I should do on the SDK call to make this call work?

2 Likes

Hi!
I have the exact same issue, one workaround is to totally dropped the monday sdk when you want to upload a file and do it by hand using axios or fetch (like this [Released] File upload via Monday's SDK client side - #3 by pepperaddict)