monday icon indicating copy to clipboard operation
monday copied to clipboard

Retrieve items with page and limit

Open wbazant opened this issue 3 years ago • 0 comments

Hi, thank you for this package, I'm finding it very useful! This is a feature request for supporting paging for retrieval of items. I have more data than can be retrieved in sixty seconds, and run into timeouts. To get around the issue, I have monkey patched the package:

monday = MondayClient(config.MONDAY_API_TOKEN)

def patch_query_arg(f, limit, page):
    def result(query):
        if 'items {' in query:
            query = query.replace('items {', 'items(limit: %s , page : %s) {'%(limit, page))
            print(query)
        return f(query)
    return result

def fetch_monday_items(board_id, limit = 1000):
    orig_f = monday.boards.client.execute
    result = []
    page = 1
    try:
        while page:
            monday.boards.client.execute = patch_query_arg(orig_f, limit = limit, page = page)
            items = monday.boards.fetch_items_by_board_id(board_id)['data']['boards'][0]['items']
            if items:
                result.extend(items)
                page+= 1
            else:
                page = 0
    except Exception as e:
        raise e
    finally:
        monday.boards.client.execute = orig_f
    return result

If more people have this problem, the package could solve it by extending fetch_items_by_board_id to do the looping like I just did - with no monkey patching, and a much simpler logic.

wbazant avatar Jul 04 '22 12:07 wbazant