Monday Server Cache

I make an API request to Monday to get all items with a specified email, if there are no matching items, I add a new item to a Monday board via our API and then shortly after (< 1 minute), I make a subsequent request via the API to get the column values of the item just created in the previous API call and the response doesn’t contain the item. If I wait a few minutes, then send the same API request, then the previously created item and it’s values are returned.

So, I’m thinking that either the server isn’t updated by the time I make the second API request or the response is being cached. I tried sending the second request with ‘cache-control: no-store’ header hoping that it would get me the freshest result from the Monday board bu that didn’t seem to work and the result still did not contain the newly created item.

The use case for this workflow is to prevent duplicate items from being added to the board so I would like to know if there is anything that I can do either through code or the Monday dashboard to prevent the duplicate records from being created.

First API call to get item by email:

getClientByEmail(email, callback) {
    let query = `query { items_by_column_values (board_id: 2551802522, column_id: "email", column_value: "${email}") { id column_values {
        id
        value
      } } }`;

    fetch("https://api.monday.com/v2", {
      method: "post",
      headers: {
        "Content-Type": "application/json",
        Authorization: process.env.MONDAY_KEY,
        "cache-control": "no-store",
      },
      body: JSON.stringify({
        query: query,
      }),
    })
      .then((res) => res.json())
      .then((res) => {
        // error handling
        callback(null, res);
      })
      .catch((mondayErr) => callback(mondayErr, null));
  }

If the above request returns no items, then I add a new item via this method:

addRecordToLeadBoard(leadInfo, callback) {
    let newLeadObject = {
      status: "New Lead",
      email: { email: leadInfo.email, text: leadInfo.email },
      location: { lat: 0, lng: 0, address: leadInfo.address_1 },
      phone_1: {
        phone: leadInfo.phone_number.replace(/\D+/g, ""),
        countryShortName: "US",
      },
      long_text2: { text: leadInfo.notes },
      status_1: "Interior",
      text5: "Website",
    };
    let vars = {
      myItemName: leadInfo.name,
      columnValues: JSON.stringify(newLeadObject),
      boardId: 2551802522,
    };

    let query =
      "mutation ($myItemName: String!, $boardId: Int! ,$columnValues: JSON! ) { create_item (board_id:$boardId, item_name:$myItemName, column_values: $columnValues) { id } }";

    fetch("https://api.monday.com/v2", {
      method: "post",
      headers: {
        "Content-Type": "application/json",
        Authorization: process.env.MONDAY_KEY,
        "cache-control": "no-cache",
      },
      body: JSON.stringify({
        query: query,
        variables: JSON.stringify(vars),
      }),
    })
      .then((res) => res.json())
      .then((res) => {
        // Error Handling
        callback(null, res);
      })
      .catch((mondayErr) => callback(mondayErr, null));
  }

After the item is created, I then shortly after make pretty much the same request but the ‘leadInfo’ object I use to populate the Monday item has different data. So in order to prevent a duplicate item, I make the first API call again (getClientByEmail) with the hopes that the response from Monday will give me the newly created item however it’s not been returning the newly created item until I retry sending the request again after a minute or two

1 Like

Hello there @noah.h and welcome to the community!

I hope you like it here :muscle:

The items_by_column_values method will give you the items with the desired value in the specified column when that value has been there for at least 32 seconds. This might take a few more seconds in times where the server traffic is very high.

I hope that helps!

Cheers,
Matias

1 Like

Hi @Matias.Monday thanks for the quick reply!

That makes sense and is very good to know.

Thanks for the help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.