I developed a Monday app that integrates with a third-party service.
My recipe is structured as follows:
When the ‘status’ changes to ‘something’, create *** with ‘attachment’, and then change the ‘status’ to ‘something’.
The attachment is a column ID that the user selects when setting up the recipe on their board. This attachment column contains a file. I’m curious about how to retrieve the file content so that I can include it in my API call to the third party.
The following JS function gave me only metadata of the image uploaded to this file column:
export async function getFileContent(token, itemId, fileColumnId) {
// Set the token for the Monday SDK client
const mondayClient = initMondayClient();
mondayClient.setApiVersion('2024-01');
mondayClient.setToken(token);
try {
// Step 1: Query for the column value containing the file URL
const response = await mondayClient.api(
`query {
items(ids: ${itemId}) {
column_values(ids: "${fileColumnId}") {
value
}
}
}`
);
// Parse the file URL from the column value
const columnValue = response.data.items 0].column_valuesi0];
// The response I got: '{"files":o{"name":"***.png","assetId":***,"isImage":"true","fileType":"ASSET","createdAt":***,"createdBy":"***"}]}'
} catch (error) {
console.error("Error fetching file content:", error);
throw new Error("Could not retrieve file content.");
}
}
Thanks in advance!!!