Updated since filter

I would like to know if this is still true: Filter API by Date
That I can’t filter items based on their updated at date.

Use case: I’ll build an app to extract data from Monday and send it to a database to be used in power bi. So if it was possible to filter the items by the update at date, I would get for sure just the data that I need to create/update in the database.

Hello,

I believe the referenced answer is still the case.

One suggestion would be to add the ‘newest_first: true’ attribute. While not exactly what you were looking for you should be able to achieve your goal. You’d have to update the limit and possibly paginate until you come across a data point that is before your last request.

query {
      items (newest_first: true) {
        id name updated_at
        
      }
    }

Yeah, but I guess it would not work. Let’s say I have an item that was created one year ago and has just been updated. It would not be considered by this filter newest_first. I would still need to get all items from board and test for the updated_at anyway.

Hello @Samuel and welcome to the community!

I hope you like it here :muscle:

Indeed that is the case. You can not use a parameter to filter using the update date as a criteria.

Having said that, I have added your case as a vote into a request for this feature.

Let us know if you have any other questions!

Cheers,
Matias

2 Likes

Hi @Samuel, I also shared your question and found that there is an indirect workaround available, if you query Activity Logs, which does have a timestamp argument, and then parse the item IDs from the response, as described here, see also the example below.

@Matias.Monday please also add my vote for Monday to provide this feature directly. It encourages inefficient use of computational resources on both sides, and it is unusual for an API not to offer this feature. It presents an obstacle to the timely and frequent synchronisation of data in Monday with other systems, an objective which is becoming increasingly important to modern businesses.

Here’s an example in Python, of how to obtain the IDs for items which have been updated since a given time.

import json
import requests

def flatten_list(input_list):
    return [item for sublist in input_list for item in sublist]

# Prepare GraphQL query to list activity logs for all boards
query = (
    "query activity_logs($from: ISO8601DateTime $page: Int)"
    "{boards{activity_logs(from: $from page: $page){id data entity}}}"
)
variables = {"from": "2023-01-01T00:00:00", "page": 1}
response = requests.get(
    url="https://api.monday.com/v2",
    json={"query": query, "variables": variables},
    headers={"Authorization": "Bearer ***"},
)

# Prepare response data
response_data = response.json()
activity_logs = flatten_list(
    [board["activity_logs"] for board in response_data["data"]["boards"]]
)

if activity_logs:  # if list is not empty

    # Filter for board and pulse (AKA item) objects
    boards = [
        json.loads(al["data"])
        for al in activity_logs
        if al["entity"] == "board"
    ]
    pulses = [
        json.loads(al["data"])
        for al in activity_logs
        if al["entity"] == "pulse"
    ]

    # Extract and deduplicate IDs for boards and items
    board_ids: set[int] = set([b["board_id"] for b in boards])    
    # Note there seem to be two possible schemas for the
    # pulse object, but both contain the item ID
    pulse_ids: set[int] = set(
        [
            *[p["pulse_id"] for p in pulses if "pulse_id" in p],
            *[p["pulse"]["id"] for p in pulses if "pulse" in p],
        ]
    )

    # Further requests can now be made using those IDs...
3 Likes

Hello @TomUK and thank you for sharing that!

I have added your vote towards this request :slightly_smiling_face:

Cheers,
Matias

Here’s a slight correction to the code above, as you’ll need to paginate through each page of activity logs, for each page of boards, until the responses return no data :+1:

query = """
query activity_logs($from: ISO8601DateTime, $board_page: Int, $log_page: Int) {
  boards(page: $board_page, limit: 100) {
    activity_logs(from: $from, page: $log_page, limit: 100) {
      id
      data
      entity
    }
  }
}
"""
variables = {"from": "2023-01-01T00:00:00", "board_page": 1, "log_page": 1}

Thank you for the correction @TomUK !

@Matias.Monday Where can we vote for this request?

Hi @GCavin,

Right here!

I have added your vote :slightly_smiling_face:

Hi Everyone

I am excited to share that you can now filter based on the last updated date in the API, regardless of wether it is a board column or not!

The key to doing so is using the "UPDATED_AT" compare attribute!

Here is an example of how to get all items that were updated in the current date

query {
  boards(ids: 1234567890) {
    items_page (query_params: {rules: [{column_id: "__last_updated__", compare_value: ["TODAY"], operator:any_of, compare_attribute:"UPDATED_AT"}]}) {
      items {
        id
        name
      }
    }
  }
}

Happy Coding!

2 Likes