Files (assets)
Any file you upload to monday.com is saved as an asset. Every asset has an ID that is used to identify it in an account.
TIP
Want to learn more about how monday.com manages files in general? Check out this article.
Assets queries
Required scope: assets:read
Querying assets returns one or a collection of assets. You can use assets at the root of your query or nest them within another query.
If you want to query one or more assets (files) by their ID, you can use the assets field as the root of your query.
query {
assets (ids: [1,2,3]) {
id
name
url
}
}
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
query : "query { assets (ids: [1,2,3]) { id name url }}";
})
});
curl --location --request POST 'https://api.monday.com/v2' \
--header 'Authorization: YourSuperSecretApiKey' \
--header 'Content-Type: application/json' \
--data-raw '{"query": "query { assets (ids: [1,2,3]) { id name url }}"}'
You can also get data from them when pulling data for a specific update or item. This is helpful if you do not know the ID of the asset you need to query.
The assets field is also supported in the Items or Updates field. If you do not know the ID of the asset you need to query, you can also query for assets as part of an Item or an Update. You will find a couple of examples below to illustrate this.
In order to lower the complexity cost of those queries, use limit
where applicable!
query {
boards (ids:1181887391) {
items (limit:100) {
assets {
id
url
name
}
}
}
}
query {
updates (limit:100) {
assets {
id
name
url
}
}
}
Arguments
Assets can receive the following arguments.
Argument | Description |
---|---|
assets_source AssetsSource | The assets source: all, columns, or gallery. |
column_ids [String] | The IDs of the columns you want to retrieve assets from. |
Fields
Each asset contains the following fields.
Field | Description |
---|---|
created_at Date | The file's creation date. |
file_extension String! | The file's extension. |
file_size Int! | The file's size in bytes. |
id ID! | The file's identifier. |
name String! | The file name. |
public_url String! | Public URL to the asset, which will be valid for 1 hour. Accessing this link will allow users without a monday.com user profile to see the file directly, while the link is valid. |
uploaded_by User! | The user who uploaded the file. Please note: this field will not return anything if the asset is a duplicate of something generated by a system. |
url String! | The URL to view the asset. This URL will only be available to users who would have access to the file, as part of your account. In case the file is stored on a Private or Shareable board, they will also need to be part of the board in question. |
url_thumbnail String | URL to view the asset in thumbnail mode. Only available for images. |
original_geometry String | The asset's original geometry. |
Assets mutations
You can upload files to monday.com using the API. Files are saved as "assets" and always belong to a parent object, which would be an item or an update.
Files endpoint
When uploading files, you should use an alternate endpoint: https://api.monday.com/v2/file
You can upload files up to 500 MB in size using this endpoint. The normal endpoint only supports files up to 1MB.
Making multipart requests
If you are making direct requests to the API, you have to use the multipart/form-data
content type, as described in this post on our community.
Depending on the language or library, you may need to construct the body of the multipart HTTP request manually. You can find a JavaScript example in this community post.
Add a file to an update
Required scope: updates:write
This API call will add a file to an existing update. The file will be added to the bottom of the update. You can find the Postman request to add a file to an update here.
mutation {
add_file_to_update (update_id: 12345678, file: YOUR_FILE) {
id
}
}
/// those are the main dependecies you'll need to have installed in this example;
const fs = require('fs');
const fetch = require('node-fetch');
/// Replace with your actual API Key
const API_KEY= "YourSuperSecretApiKey";
/// Notice the /file/ endpoint - only this endpoint will support variables in this type of call
const url = 'https://api.monday.com/v2/file';
/// This is your mutation query - can also be adapted to send files to file columns instead
const query = 'mutation ($file: File!) { add_file_to_update (update_id: 123456789, file: $file) {id}}'
///This is the mapping for the API call, where you specify that a variable should be considered as the variables[file] of the request.
///This can be called "image", or simply file - as long as it matches the name of the multipart request later down the line.
var map = {"image":"variables.file"};
/// this is the path to the file you'd like to upload to monday.com
var upfile = `./300px-All_Right_Then,_Keep_Your_Secrets.jpg`;
var data = "";
const boundary = "xxxxxxxxxxxxxxx";
fs.readFile(upfile, function(err, content){
// simple catch error
if(err){
console.error(err);
}
//below, we will construct a multipart request. Take a look at the "name" within each part, as those will refer to different parts of the API call.
// construct query part
data += "--" + boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"query\"; \r\n";
data += "Content-Type:application/json\r\n\r\n";
data += "\r\n" + query + "\r\n";
// construct map part
data += "--" + boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"map\"; \r\n";
data += "Content-Type:application/json\r\n\r\n";
data += "\r\n" + JSON.stringify(map)+ "\r\n";
// construct file part - the name needs to be the same as passed in the map part of the request. So if your map is {"image":"variables.file"}, the name should be image.
data += "--" + boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"image\"; filename=\"" + upfile + "\"\r\n";
data += "Content-Type:application/octet-stream\r\n\r\n";
var payload = Buffer.concat([
Buffer.from(data, "utf8"),
new Buffer.from(content, 'binary'),
Buffer.from("\r\n--" + boundary + "--\r\n", "utf8"),
]);
// construct request options
var options = {
method: 'post',
headers: {
"Content-Type": "multipart/form-data; boundary=" + boundary,
"Authorization" : API_KEY
},
body: payload,
};
// make request
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json));
});
Arguments for add a file to an update
This mutation includes the following arguments.
Argument | Description |
---|---|
update_id Int! | The unique identifier of the update where the file will be added to the bottom. You can also use a reply ID to add the file to an update's reply. |
file File! | The file to upload. |
Add a file to the file column
Required scope: boards:write
This mutation call will add a file to the file column of a specific item.
mutation {
add_file_to_column (item_id: 87654321, column_id: "files", file: YOUR_FILE) {
id
}
}
var fs = require('fs');
var fetch = require('node-fetch'); // requires node-fetch as dependency
// adapted from: https://gist.github.com/tanaikech/40c9284e91d209356395b43022ffc5cc
// set filename
var upfile = 'sample.png';
// set auth token and query
var API_KEY = "MY_API_KEY"
var query = 'mutation ($file: File!) { add_file_to_column (file: $file, item_id: 123456789, column_id: "files") { id } }';
// set URL and boundary
var url = "https://api.monday.com/v2/file";
var boundary = "xxxxxxxxxx";
var data = "";
fs.readFile(upfile, function(err, content){
// simple catch error
if(err){
console.error(err);
}
// construct query part
data += "--" + boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"query\"; \r\n";
data += "Content-Type:application/json\r\n\r\n";
data += "\r\n" + query + "\r\n";
// construct file part
data += "--" + boundary + "\r\n";
data += "Content-Disposition: form-data; name=\"variables[file]\"; filename=\"" + upfile + "\"\r\n";
data += "Content-Type:application/octet-stream\r\n\r\n";
var payload = Buffer.concat([
Buffer.from(data, "utf8"),
new Buffer.from(content, 'binary'),
Buffer.from("\r\n--" + boundary + "--\r\n", "utf8"),
]);
// construct request options
var options = {
method: 'post',
headers: {
"Content-Type": "multipart/form-data; boundary=" + boundary,
"Authorization" : API_KEY
},
body: payload,
};
// make request
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json));
});
Arguments for add a file to the file column
This mutation will accept the following arguments.
Arguments | Description |
---|---|
item_id Int! | The unique identifier of the item where the file will be added. |
column_id String! | The unique identifier of the column where the file will be added. |
file File! | The file to upload. |
You can find the Postman request to add a file to the file column here.
Have questions?
Join our developer community! You can share your questions and learn from fellow users and monday.com product experts.
Don’t forget to search before opening a new topic!
Updated 5 days ago