Skip to main content

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_values[0];
      // The response I got: '{"files":[{"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!!!

Hello there @Oded282,

You can use a query like this one:

{
  items(ids: 1234567890) {
    assets(column_ids: "column_id_here") {
      name
      id
      public_url
    }
  }
}

What do you think?

Cheers,
Matias


Great! thanks for your reply 🙂
Can I use a GraphQL query to directly retrieve the image binaries, or would I need to make a separate API call to the URL for that?


@Oded282 if you are talking about the binary code for the file, you can not get that via the API. You can only get the public_url to download the file. Once you have the file, you can manipulate it at will 😀


Thanks you for the quick response!


Happy to help!!