EDIT 2: Finally got it, I used the API & a ID generator for HTTPS
requests and used the provided &before=
parameter. The &before=
parameter uses dates as the arguments, so I had to grab the last action from one request, get the date from that, and provide it for the &before parameter. Then for every array element that had 1000 elements, I popped the last element because I'd end up with duplicate actions.
Now, I ended up with actions that look like this: [[actions],[actions],[actions],[actions]]
and so on, so I used Merge/flatten an array of arrays 's answer to make it all [actions]
. Then I used bracket notation object["key"] = value
to set / replace the actions with the actions from my HTTPS
requests, and it came out to a VERY large file, and it took quite a while to produce this file, it came out to around 99.5 MB
.
this is my whole index.js test file:
const https = require('https');
const fs = require('fs');
var boardinfo = "";
https.get({
hostname: 'trello.com',
path: `/b/....json`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var data = "";
r.on('data', (d) => {
data+=d;
})
r.on('close', () => {
boardinfo = JSON.parse(data);
});
})
var actions = [];
(function untilDeath(beforeval) {
https.get({
hostname: 'api.trello.com',
path: `/1/boards/.../actions?limit=1000${beforeval ? `&before=${beforeval}` : ``}`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var cmpdta = "";
r.on('data', (d) => {
cmpdta+=d;
})
r.on('close', () => {
cmpdta = JSON.parse(cmpdta);
if(cmpdta.length < 1000) {
if(cmpdta.length) actions.push(cmpdta);
return makeFile(info, [].concat.apply([], actions), fileName);
} else
untilDeath(cmpdta[999].date);
cmpdta.pop();
actions.push(cmpdta);
});
r.on('error', () => {
throw new Error('Error');
});
});
})();
function makeFile(trelloBoard, actions) {
trelloBoard["actions"] = actions;
fs.createWriteStream('./full-board.json');
fs.writeFile(`./full-board.json`, JSON.stringify(trelloBoard, null, `\t`), (c) => {
if(c) console.log(c);
});
}
EDIT: Disappointingly, this also only fetches 1000 actions, even with saving the JSON file manually, it still gives 1000 actions.
I easily resolved this with a HTTPS User-Agent
header.
const https = require('https');
https.get({
hostname: 'trello.com',
path: '/b/....json',
headers: {'User-Agent': 'some-random-user-agent'}
}, (r) => {
var str = "";
r.on('data', (d) => {str+=d});
r.on('close', () => {console.log(str)})
})