My name is Lorentz and I have some questions about using PHP with monday. I am working with the monday API and I have connected my monday with PHP. But know I am looking for a way to count all the data that I have called in. The query that I made to get data is: query { boards (ids: xxxxxxxxx) { groups { title items { name id }}}}
. This calls back all the items form all the groups. But I only want all the items from one specific group. And I also want to a piece of code the count all the items so that I have the total amount of items. Can someone give me a step in the right direction?
Hello @lorentz,
You can get items from a specific group by specifying the group id.
In your case, it will look like something like below:
query { boards (ids: xxxxxxxxx) { groups(ids: groupIdHere) { title items { name id }}}}
Concerning the number of items in a group, currently, as far as I’m aware, monday.com doesn’t offer a way to know how many items there are in a group. However, a hack you can use is to specify a high limit of items to return from the query and then when you receive the array of items, you can get the length of the items array.
For example:
query { boards (ids: xxxxxxxxx) { groups { title items(limit: 20000) { name id }}}}
You can read more about groups and items in the documentation
Hey @lorentz
Great question! And in my opinion, the response from @kolaai is exactly on point. You will need to specify the Group ID (or use an array of IDs as string, separated by comma).
We don’t offer an option to count the number of items via API currently, so that’s very accurate too.
-Alex
Hello @AlexSavchuk, thank you for you quick response! But I have one more question to follow up on this. Do you any website or form or maybe you know your self how to use php to filter the data from the API?
EDIT: Is the data that you recieve also a array for PHP?
Thanks in advance.
I’m glad Alfred and I could help
The response will be a JSON body. I’d recommend looking through how to filter JSON results in PHP generally. Here’s a StackOverflow thread that might be helpful:
-Alex
Hey Alex, how would we do this in version 2023-10? The max items one can get now is 100, so say user has 20,000 items on board, how would I get the count? make 200 calls?
I want to count items in each group.
Hello there @gary,
You can either use something like this:
{
boards(ids: 1234567890) {
groups(ids: "topics") {
items_page (limit:50000){
cursor
items {
id
name
}
}
}
}
}
Or use pagination with the cursor like:
{
boards(ids: 1234567890) {
groups(ids: "topics") {
items_page (limit:100){
cursor
items {
id
name
}
}
}
}
}
and then use the cursor to get the next page and so on:
{
boards(ids: 1234567890) {
groups(ids: "topics") {
items_page (limit:100, cursor: "MSw5NzI4MDA5MDAsaV9YcmxJb0p1VEdYc1VWeGlxeF9kLDg4MiwzNXw0MTQ1NzU1MTE5"){
cursor
items {
id
name
}
}
}
}
}
Let me know how that goes!
Cheers,
Matias
Thanks for that, first query works but can I ask you whats the max limit we can use for that query?
also when using query_params in item_page, the limit is decreased to 500? is that right?
here is the query I have which gives error that limit can be max 500.
let query =
"query { boards(ids:" +
this.boardID +
"){ items_page(limit:50000, query_params: {ids: [" +
itemIdsArray +
"]}) { items {id name group { title id color}} } }}";
Basically I need to get only those items which are in that that idsArray, is there any better way?
I can filter them after getting them but I want to know if there is a better way?
UPDATE
I did try that first solution and it did not give me any error when I used 50,000 limit, but once I got the items back, it is still caping it to 500 items only!
So that solution does not really work! is there any other better way?
I don’t think second solution is really feasible, it will hit the complexity budget if I get all 50,000 items in a loop(get 500, use cursor to get next) on board to count them
Hello again @gary,
I am sorry about the 500 items limit. I forgot about that limitation. My bad. I asked the team to add an exception when a limit bigger than 500 is used.
In this case you can go with the second approach. You can avoid hitting the complexity limit by checking the complexity points usage and creating a mechanism that waits for the quota to reset before continuing with the next batch. And then do the filtering.
Or you could not use the limit, but use the IDs instead. In that way, you can pass an array of IDs to get only those items (take into account that you might also needd use batches here and not add all of the IDs together in one call). The limit of IDs is 100.
Let me know if you have any other questions!
Cheers,
Matias