Testing the Trello API without leaking your key and token

Trello's API has been around for a long time, and most examples put the API key and token in the query string: ?key=…&token=…. That works, and it also puts your credentials in every log line, proxy and shared screenshot that shows the URL. There's a better way that Trello also accepts.

Step 1: Key, token and environment

Create a Power-Up in the Trello admin portal to get an API key, then generate a token for your test user from the same page.

VariableValue
baseUrlhttps://api.trello.com/1
trelloKeythe API key, marked as secret
trelloTokenthe token, marked as secret

On the collection, add the header through a pre-request script, so every request gets it and the URL stays clean:

JavaScript
const key = pm.environment.get('trelloKey');
const token = pm.environment.get('trelloToken');
pm.request.headers.set('Authorization', `OAuth oauth_consumer_key="${key}", oauth_token="${token}"`);

Requestarium masks secret values in history and reports, but only where it knows they're secrets. Credentials in a header are much easier to keep out of logs than credentials in a URL.

Step 2: Boards and lists

HTTP
GET {{baseUrl}}/members/me/boards?fields=name,url&filter=open
JavaScript
const board = pm.response.json().find((b) => b.name === 'API tests');
pm.test('test board exists', () => pm.expect(board).to.exist);
pm.environment.set('boardId', board.id);
HTTP
GET {{baseUrl}}/boards/{{boardId}}/lists?fields=name
JavaScript
const lists = pm.response.json();
pm.environment.set('todoListId', lists.find((l) => l.name === 'To do').id);
pm.environment.set('doneListId', lists.find((l) => l.name === 'Done').id);

Step 3: Create a card

HTTP
POST {{baseUrl}}/cards?idList={{todoListId}}&name=API test {{$timestamp}}&desc=Created by API tests
JavaScript
const card = pm.response.json();
pm.test('card created', () => {
  pm.expect(pm.response.code).to.equal(200);
  pm.expect(card.idList).to.equal(pm.environment.get('todoListId'));
});
pm.environment.set('cardId', card.id);

Trello answers 200, not 201, for creates. Test for what the API does, not what REST textbooks say.

Step 4: Move it

HTTP
PUT {{baseUrl}}/cards/{{cardId}}?idList={{doneListId}}
JavaScript
pm.test('moved to Done', () => pm.expect(pm.response.json().idList).to.equal(pm.environment.get('doneListId')));

Step 5: Errors and limits

Trello's errors are often plain text, not JSON: an unknown card id answers 400 with invalid id, and a bad token answers 401 with invalid token. Check the body as text:

JavaScript
pm.test('bad id refused', () => {
  pm.expect(pm.response.code).to.equal(400);
  pm.expect(pm.response.text()).to.include('invalid');
});

Over the rate limit, Trello answers 429. A run that creates many cards should use --delay 150 or so to stay under 100 requests per 10 seconds.

Delete the card in a cleanup step: DELETE {{baseUrl}}/cards/{{cardId}}.