Skip to content

Instantly share code, notes, and snippets.

@jimmysawczuk
Created September 15, 2017 15:32
Show Gist options
  • Save jimmysawczuk/88dff03ddc4bb9547326ac8654a3577e to your computer and use it in GitHub Desktop.
Save jimmysawczuk/88dff03ddc4bb9547326ac8654a3577e to your computer and use it in GitHub Desktop.
Close all daily boards

Copy these files into a new directory, then run composer install, then get your API key and token, then run.

{
"require": {
"guzzlehttp/guzzle": "^6.3"
}
}
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client;
// Generate an API key and token from this page: https://trello.com/app-key
$api_key = '<YOUR API KEY HERE>';
$token = '<YOUR TOKEN HERE>';
$username = '<YOUR USERNAME>';
$boards = json_decode($client->request('GET', "https://api.trello.com/1/members/{$username}", [
'query' => [
'key' => $api_key,
'token' => $token,
],
])->getBody(), true);
foreach ($boards['idBoards'] as $boardID) {
$board = json_decode($client->request('GET', "https://api.trello.com/1/boards/{$boardID}", [
'query' => [
'key' => $api_key,
'token' => $token,
],
])->getBody(), true);
// Only want to consider personal boards
if ($board['idOrganization'] !== null) {
continue;
}
// If the board is already closed, we can skip it.
if ($board['closed']) {
continue;
}
if (preg_match('#^[A-Za-z]+ \d{1,2}, \d{4}#', $board['name'])) {
echo "To be closed: {$board['name']}\n";
$res = $client->request('PUT', "https://api.trello.com/1/boards/{$boardID}", [
'query' => [
'key' => $api_key,
'token' => $token,
'closed' => 'true',
],
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment