Hi everyone, I’ve hit a snag while trying to upload a file to a column using the Monday SDK. Below is the snippet I’m working with:
import initMondayClient from 'monday-sdk-js';
import { Logger } from '@mondaycom/apps-sdk';
import path from 'path';
import fs from 'fs';
import FormData from 'form-data';
export async function changeColumnValue(token, itemId, columnId) {
const formData = new FormData();
const filePath = path.join(__dirname, 'test.txt');
formData.append('variables[file]', fs.createReadStream(filePath), 'test.txt');
formData.append(
'query',
`mutation ($file: File!) {
add_file_to_column (item_id: ${itemId}, column_id: "${columnId}", file: $file) {
id
}
}`,
);
try {
const response = await fetch('https://api.monday.com/v2/file', {
method: 'POST',
headers: {
Authorization: token,
...formData.getHeaders(),
},
body: formData,
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
throw new Error(error.message);
}
}
When I run this, I encounter the following error:
{ “error_message”: “Unsupported query”, “status_code”: 400 }
I’m using Node v18.0.0 and have taken this code as a base from the quickstart-integrations-monday documentation, with minor adjustments to test some functionalities. The goal here is to craft a function that receives itemId
, columnId
, and a token
, and uploads a file located on my server to the specified column/item.
Would appreciate any insights or suggestions on what I might be doing wrong or missing. Thanks in advance!