Uploading a file to monday.com with variables - example in NodeJS

Hey there, awesome developers! :tophat:

Ever wanted to upload a file to our API using variables without using our SDK? You’re in the right place!

Today, I wanted to share a code example you can use as a reference point to making File upload calls to monday.com, including variables. This can make it easier to make the actual API call, instead of using hard-coded values in the call itself. This also helps make escaping JSON easier.

You can find the code example here with comments:

Code example - uploading files with variables using Node

In general, you can take the logic of the code example above, and apply it the programming language you are using. You will be sending a request that consists of 4 parts:

  • Query:
    The actual API query you’d like to make. In this case, either upload a File to the Files column, or to the Updates section.
  • Variables:
    Your GraphQL variables, where you can store either the Update ID to be used, or the Item ID and the File column ID to be referenced in the mutation. This is useful as it allows you to avoid an additional layer of escaping JSON;
  • Map:
    This is the part of the request where you include the name of your variables.file request part. For example:

var map = {“image”:”variables.file”}

This allows us to use variables in the call, and to also include a different name for the file we upload, if necessary.

  • Variables.file (has to match the Map name)
    This is where you are passing the actual file to be uploaded.

To sum up, you will be making a multipart/form-data request here, which is somewhat different from making the usual “application/json” requests for Queries and Mutations. You can find some more examples of multipart/form-data requests and GraphQL below:

This code example is based on another example that Dipro made earlier, constructing the request using boundaries and creating a stream of the File to upload before making the API call:

Uploading a file to monday.com without variables

I hope this helps you make more efficient API calls when uploading files to monday.com :slight_smile:

-Alex