Created
March 19, 2018 00:28
-
-
Save justanotherdot/11433340ffe306561562dbaa7cc60976 to your computer and use it in GitHub Desktop.
Batch delete of archived cards with Trello API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import time | |
API_KEY = "" | |
API_TOKEN = "" | |
table_id = "" | |
url = "https://api.trello.com/1/boards/{}/cards/closed/?key={}&token={}".format(table_id, API_KEY, API_TOKEN) | |
response = requests.request("GET", url) | |
results = json.loads(response.text) | |
# "To help prevent strain on Trello’s servers, our API imposes rate limits per | |
# API key for all issued tokens. There is a limit of 300 requests per 10 | |
# seconds for each API key and no more than 100 requests per 10 second | |
# interval for each token. If a request exceeds the limit, Trello will return | |
# a 429 error." | |
# | |
# see https://help.trello.com/article/838-api-rate-limits | |
count = 0 | |
for o in results: | |
if count != 0 and count%100 == 0: | |
print("Serviced {} items so far".format(count)) | |
time.sleep(11) | |
if o['closed']: | |
url2 = "https://api.trello.com/1/cards/{}/?key={}&token={}".format(o['id'], API_KEY, API_TOKEN) | |
print("DELETE {}".format(url2)) | |
response = requests.request("DELETE", url2) | |
print(response.status_code) | |
count += 1 |
Thanks! Here are my quick and dirty modifications to unarchive all archived cards and move them to specified "Closed" list:
if o['closed']:
url2 = "https://api.trello.com/1/cards/{}/?closed=false&idList=InsertIdOfYourDestinationList&key={}&token={}".format(o['id'], API_KEY, A
print("UNARCHIVE {}".format(url2))
response = requests.request("PUT", url2)
print(response.status_code)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still working as of today. Very helpful to unclutter the search from long gone cards.