Hi, I’m trying to programmatically upload a file as a new version.
What I have so far:
var boardId = 25509xxxxx;
var itemId = 25509xxxxx;
var assetId = 4888xxxxx;
const uploadQuery =
`
mutation ($file: File!) {
add_file_to_column (item_id: ${itemId}, column_id: "files", file: $file) {
id
}
}
`;
var url = "https://api.monday.com/v2/file";
var buf = fs.readFileSync("./package.json");
var formData = new FormData();
formData.append("query", uploadQuery, { contentType: "application/json" });
formData.append("variables[file]", buf, { contentType: "application/octet-stream", filename: "package.json" });
var options = {
method: 'post',
headers: formData.getHeaders(),
body: formData,
};
options.headers.Authorization = user.token;
var uploadResponse = await fetch(url, options);
var json = await uploadResponse .json();
var jsonChange = JSON.stringify({
updated_file:
{
fileType: "ASSET",
assetId: json.data.add_file_to_column.id,
previousAssetId: assetId,
name: "package.json",
isImage: false,
isVersion: true,
}
}).replace(/"/g,'\\"');
const updateQuery =
`
mutation {
change_column_value (board_id: ${boardId}, item_id: ${itemId}, column_id: "files", value: "${jsonChange}") {
id
}
}
`;
var updateResponse = await monday.api(updateQuery, { token: user.token });
And it works, except a file is duplicated in a column. I also tried to send removed_file with v1 asset id and it works. But after that you can’t access v1 anymore.
And run it, then it kinda works, nothing is duplicated, you get only one file in a column, but if you expand file info, there is no V1, only the second (uploaded) version.
Hoping to hear from you soon.
Any update on this?? This API is ridiculous, nothing is supported. You cannot add a new version, you cannot rename files, you cannot download a file in a safe way (private url with auth), you cannot get the order of subitems, etc. etc. I can go on forever.
A request was created for this as for the ability to rename files, the ability to download a file without using the public URL and the index for subitems. We added your votes!