Question

How to use Javascript to return yes or no value if monday.com value exists?

  • 24 February 2022
  • 1 reply
  • 164 views

Userlevel 1
Badge

How can I get this to return a yes or no if it exists?

 

const API_KEY = "X",
      boardId = X;

const sendRequest = async (payload) => {
  const response = await fetch("https://api.monday.com/v2/", {
    method: "POST",
    body: JSON.stringify(payload),
    headers: {
      "content-type": "application/json",
      authorization: API_KEY,
    },
  });

  const results = await response.json();

  return results;
};

const getItem = async () => {
  const query = `
      query {
        items_by_column_values (board_id: ${boardId}, column_id: "email_1", column_value: "${inputData.email}") {
          id
          name
        }
      }`;

  const response = await sendRequest({
    query,
  });

  const results = response.data['items_by_column_values'][0].id;

  return results;
};


const response = await getItem();


output = {
   id: response
};


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +11

Hey there, @alexadagostino!

I can’t advise on how to do that using a Code step. But, it looks like you might be trying to run a search in monday.com to get certain column values, and check whether they were found or not, is that correct? 

If so, as an alternative you could use the Get Item by Column Value search action for monday.com to run the search, then you could add a Filter step or use Paths to check whether the _zap_search_was_found_status field is true or false (true indicates that it found something, false indicates that nothing was found). Would that work for your desired workflow here?