Items_page sort items by updated_at/created_at

I am trying out the new items_page endpoint.

What I am trying to achieve is to fetch the 10 most recent items assigned to me. Where “recent” implies that the item has been created or updated recently.

I am current using this query:

boards (ids: [3576472011 3576476533]){
    id
    name
    items_page (query_params: {rules: [{column_id: "person", compare_value: ["assigned_to_me"], operator: any_of}
    
  ]}, limit: 500) {
      items {
        id
        created_at
        updated_at
      }
    }

   
  }

I fetch up to 500 items per board and then do the sort myself by querying the created_at and updated_at dates, is there a way to sort the items in the request so that I do not have to fetch 500 items and potentially miss out on 501-xxxx?

hi @timovanderkamp

Have you tried the order_by on the items_page as described here Migration guide - 2023-10

Not sure if created_at and updated_at are supported and how this would work on multiple boards. It does seem to work with the creation_log, but not sure if it compares the person or the date part of the creation_log.

query {
  boards (ids:123456789) {
    items_page(query_params: {
      order_by: [
        {column_id:"creation_log4", direction: desc}
      ]
    }) {
      items {
        id
        name
      }
    }
  }
}

Hi @basdebruin ,

Yes I have tried the order_by query param but with no success. The creation_log column seems to be a custom column, I can not find it on my boards.

hi @timovanderkamp

What kind of columns are your created_at and updated_at. The “creation log” column is just another column that you can add to your board.

I think I’m having the same issue.

updated_at and created_at seem to be fields that are added by Monday, so they aren’t columns on the board. However it does not allow you to use those fields to order_by.

The fields clearly exist as you can see it returns data in the first screen shot. However when you try use it, it gives an error saying that it does not exist.

hi @justinvandyk

See some good news here: https://community.monday.com/t/using-order-by-creation-date-in-2023-10/66116/4

Hi @basdebruin

It says the page does not exist or I do not have access :thinking:

hi @timovanderkamp

Oops, this is a closed workspace (developers only). The latest from monday was:

1 Like

Thank you @basdebruin for bringing the good news!!

Thanks Bas! Has there been any movement on this? I’ve tested again but query still fails in bot 2023-10 and dev version of the API.

query_params: {
      order_by: [
        {column_id:"updated_at", direction: desc}
      ]
    }

hi @justinvandyk

No update yet, but expected this week / next week (as mentioned by monday team)

1 Like

Hello everyone! This will be coming soon. We will update here when it does!

1 Like

Hello everyone!

You can use these queries now to order your results (documentation on the way):

{
  boards(ids: [1234567890]) {
    items_page(
      query_params: {order_by: [{column_id: "__creation_log__", direction: desc}]}
    ) {
      items {
        id
        created_at
      }
    }
  }
}
{
  boards(ids: [1234567890]) {
    items_page(
      query_params: {order_by: [{column_id: "__last_updated__", direction: asc}]}
    ) {
      items {
        id
        updated_at
      }
    }
  }
}

Cheers,
Matias

Dear @Matias.Monday, I was trying to use order with cursor and got this kind of error.

"Invalid request: You must provide either a ‘query_params’ or a ‘cursor’, but not both. Use ‘query_params’ for the initial request and ‘cursor’ for paginated requests.

I have removed query_params to do the pagination via cursor. But it seems the responses aren’t ordered. How can we do ordered pagination?

Thanks,
Nairi

hi @nairihar

In your initial query you can specify the order_by and return the cursor as an output field. As log as the cursor is not null you do a query like this:

query getItemValuesInBoard ($columnId: [String!], $cursor: String!) {
          next_items_page (limit:100, cursor: $cursor) {
            cursor
            items {
              id
              name
              column_values (ids: $columnId) {
                id
                value
                text
                ... on DependencyValue {
                  id
                  value
                  linked_item_ids
                }
              }
            }
          }
        }

The next_items_page query does not accept the order by as that was already specified in the initial query

1 Like

Thank you @basdebruin !!