Skip to main content

For some reason my add_file_to_column query costs is 100001 for a small 2KB file.


What can I do to reduce the api query budget size of the upload?


@Matias.Monday Any pointers on how to make this more efficient?


async function uploadAndRemoveFile(upfile, token, itemId, columnId) {
try {
const affordability = await canAfford(token, 100001)
console.log("Can Afford Query: " + affordability.canAfford)
if(affordability.canAfford)
{
const mondayClient = initMondayClient();
mondayClient.setToken(token);
console.log("UPLOAD AND REMOVE FILE");
console.log("upfile: " + upfile);
console.log("itemId: " + itemId);
console.log("columnId: " + columnId);

const filename = path.basename(upfile)

const query = `mutation($item_id: ID!, $column_id: String!, $file: File!) {
add_file_to_column(item_id: $item_id, column_id: $column_id, file: $file) {
id
}
}`;

// Define variables for the mutation
const variables = {
"item_id": itemId,
"column_id": columnId
};

// Prepare the map object to associate the file variable with the form field
const map = {
"file": "variables.file"
};

// Read the file content
const content = await fs.promises.readFile(upfile);

// Create an instance of FormData
const formData = new FormData();
formData.append('query', query);
formData.append('variables', JSON.stringify(variables));
formData.append('map', JSON.stringify(map));
formData.append('file', content, {filename: filename});

// Define the fetch options
const options = {
method: 'POST',
headers: {
"API-Version": "2024-01",
"Authorization": "Bearer " + token
// 'Content-Type': 'multipart/form-data' header will be added automatically by the FormData instance
},
body: formData
};

const response = await fetch('https://api.monday.com/v2/file', options);
const jsonResponse = await response.json();
console.log('Response status:', jsonResponse);
return jsonResponse.status_code
}
} catch (err) {
console.error("Error in uploadAndRemoveFile:", err);
return '500';
}
}

I get this frequently


[0] Failed to upload file: {
[0] errors: [
[0] 'Complexity budget exhausted, query cost 100001 budget remaining 99951 out of 5000000 reset in 11 seconds'
[0] ],
[0] error_code: 'ComplexityException',
[0] status_code: 429,
[0] account_id: XXXXXXXXX
[0] }

Hello there @ianhunter373,


I believe there is no way to make this particular mutation lighter.


You can always calculate the usage of the complexity points quota and create a mechanism to avoid hitting the limit 😀


Cheers,

Matias


Reply