Get email addresses of all users in people columns of an item

Trying to use the API to return email address(es) for any people columns for a given item.

It would seem that “email” is not a valid field for “persons_and_teams” and I am only able to get the ID/s. I’m assuming there is a way to accomplish this using variables or nesting queries, but I just haven’t learned enough about QraphQL yet :slight_smile:

It would also be nice if there was a way to filter the returned data to only show people columns that are not empty. That filter only seems to work on items page, but couldn’t figure out how to make that work with just one specific item. (there are 5 people columns on the board, and typically not all of them are set)

Was hoping someone could point me in the right direction for any work arounds to accomplish this!

Thanks,

Matt

Its actually rather simple - once you query the people column for persons_and_teams you want to filter kind == "person" and map the id to userIds, and filter kind == "team" and map the id to teamIds for the following query:

query($userIds: [ID!], $teamIds: [ID!]){
 users(ids:$userIds){
  id
  email
  name
 }
 teams(ids:$teamIds) {
    id
    users {
      id
      email
      name
    }
  }
}

The monday graphql implementation lacks directives that would allow you to direct the graphql resolver to create these maps and execute secondary queries. So you have to just get the first set of results and then make another query.

you may need to modify your original query to return kind in addition to id for persons_and_teams

1 Like

Cody,

Thank you so much for the quick reply and taking the time to help me understand this better!

Perhaps you’d be able to help me understand how to adapt the solution you’re suggesting to my scenario?

My query looks like below. I am specifying the ID’s as there are additional people columns on the board I do not want. I am trying to use Column Values V2 to only return the specific subfield and not the entire JSON string.

query{
  items (ids:[5545187806]) {
    column_values (ids: ["person", "people", "people7", "people2", "people9"]) {
      ... on PeopleValue {
        persons_and_teams  {
          id
          kind  
        }
      }
    }
  }
}

Below, I get the Id’s of persons and teams, but I’m not following how to populate/map those in to variables for the subsequent query(ies) to get the user’s/team members’ emails. I’m sure I’m looking at this the wrong way. I was, however, able to use Make’s “Monday Get an Item” module along with a combination of array mapping, merging, deduplication into a String to get the list of ID’s and then send that via the API, but I can’t help but think this could be done in a single GraphQL request. If a single request (with multiple queries) isn’t the answer, then I think I still have a workable (but seemingly inefficient) method using Make/Monday.

(And thank you for pointing out that Monday’s implementation doesn’t support directives to create maps. I was working down that path with some examples on GraphQL.org and wasn’t getting anywhere)

{
  "data": {
    "items": [
      {
        "column_values": [
          {
            "persons_and_teams": null
          },
          {
            "persons_and_teams": [
              {
                "id": "14550468",
                "kind": "person"
              },
              {
                "id": "28537619",
                "kind": "person"
              }
            ]
          },
          {
            "persons_and_teams": [
              {
                "id": "14550468",
                "kind": "person"
              },
              {
                "id": "16817987",
                "kind": "person"
              }
            ]
          },
          {
            "persons_and_teams": [
              {
                "id": "51179088",
                "kind": "person"
              }
            ]
          },
          {
            "persons_and_teams": [
              {
                "id": "354444",
                "kind": "team"
              }
            ]
          }
        ]
      }
    ]
  },
  "account_id": 123456
}
1 Like

Assuming you’re using Javascript for this…

const userIds = [];
const teamIds = [];
for (const cv of data.items.column_values) {
   const persons = cv.persons_and_teams.filter((pt)=> pt.kind === "person")
   if (persons) {
    const personIds = persons.map((pv)=> pv.id);
    userIds.push(...personIds)
   }
   const teams = cv.persons_and_teams.filter((pt)=> pt.kind === "team");
   if (teams) {
    const tempTeamIds = teams.map((pv)=> pv.id);
    teamIds.push(...tempTeamIds);
   }
}

Now you’ve got the userIds and teamIds for the next query.

Unfortunately there is no way to do this in less than two queries, sent in two separate requests to monday.com. You get the first results, then with code, build your two arrays to use as variables in the next query. (look up graphql variables, you will be in a lot of pain if you try to put the values into your query string!, the monday javascript client does accept variables)

Don’t overthink trying to get this in a single request - there is latency but its not that great. Unless your primary concern is that using Make you end up with more make operations?

IF using make, you should be able to use graphql variables, and the Execute GraphQL Query module (probably the one by The Monday Man that supports API-Version 2023-10). Manipulating the arrays down may take effort and expirimentation, but you’d be flattening the cv.persons_and_teams arrays into a single array, then process that array. If you’re persistent you can create all of that in IML within the field defining the variable in the second Execute GraphQL Query module. So you won’t need additional modules. But my make is rusty and its a saturday :wink:

1 Like

Hi Cody,

Thanks again for your willingness to provide such detailed suggestions! I’m not a js guy, but your feed back on having to use two requests was helpful. In the end, using that direction along with some (more like lots) of experimentation with Make.com to transform the data has worked out. Thanks!

Matt

1 Like

Thank you @codyfrisch for the help here!