Hi everyone. I ned a little help to fix my solution.
So, I’m trying to get all the data from board cards, including the attachments and comments. To do that I used Nested properties and it works perfectly if you trying to do attachments only. But with actions you have to specify limits. And it returns the pure list without any info if there is a next “page” exists. So I decided yo use “since” and “before” together in the request.
Of course, after some filtering and calculations because API retrieves list not by date but in the same order as you can see them in a board.
So, my code part for it is kinda huge, but it’s not the main proble here.
Firstly, I’m getting all the cards ids:
the make_trello_request is my shortcut to perform request with auth data
board_cards_ids = make_trello_request(BOARD_CARDS_LINK, query={"cards": "all", "fields": "id", "sort": "-id"})
It gives me a list of card’s {“id”:“value”} dicts. It’s sorted from nearest to the oldest but I want the opposite so I made a quick calculation to get closer to the problem
ids = [(card["id"], datetime.datetime.fromtimestamp(int(card["id"][0:8], 16))) for card in board_cards_ids]
id_times_list = [item[1] for item in ids]
# make an order from older to newer
id_times_list.reverse()
# new list cards with sorted ids y creation time
ids_sorted = []
for time2 in id_times_list:
for id, time1 in ids:
# check for repeated times since somw cards can be added at the same times (like default ones)
if time2 == time1 and id not in ids_sorted:
ids_sorted.append(id)
As result, I have a ids_sorted sorted list of cards ids:
[‘5606f01b90c47913f1b9ad4e’, ‘5606f01b90c47913f1b9ad4d’, ‘5606f01b90c47913f1b9ad4c’, ‘5606f01b90c47913f1b9ad4b’, ‘5606f01b90c47913f1b9ad4a’, ‘5606f01b90c47913f1b9ad42’, ‘5606f01b90c47913f1b9ad40’, ‘6344528c5efb3600de8b640e’, ‘63469dea69db4a01b9017129’, ‘634d6fa9a347fb00d0303262’, ‘63580221ac81c7007e2df7f3’]
In my example it’s 11 ids here, but on the real board it’s more than 1000.
So I begin iterate them by 100 items chunk to avoid Rate Limit:
while True:
if start_index >= len(id_times_list):
break
index_end = start_index + (limit - 1) if start_index + (limit - 1) <= len(id_times_list) else len(id_times_list) - 1
board_cards = make_trello_request(
BOARD_CARDS_LINK,
query={
"cards": "all",
"attachments": "true",
"attachment_fields": "all",
"actions": "commentCard",
"limit": limit,
"since": ids_sorted[start_index],
# next 'limit' elements in current chunk
"before": ids_sorted[index_end]
}
).json()
cards_data += board_cards
start_index += limit
The problem is it gaves me only 4 item, because if you will look on their dates
[datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2015, 9, 26, 22, 20, 59), datetime.datetime(2022, 10, 10, 20, 12, 44), datetime.datetime(2022, 10, 12, 13, 58, 50), datetime.datetime(2022, 10, 17, 18, 7, 21), datetime.datetime(2022, 10, 25, 18, 34, 57)]
you will see there are a few cards which has the same creation time and it seems like API retirns only one of them.
On the real board it returns 50 cards instead of 440. Seems it’s also because of the date.
Also, some boards returned several times. So I guess I am missing something.
Is there any solution? Except getting only attachments and then iterate every card to get it’s comments? I’m trying to avoid unnecessary API calls.
Thanks in advance.