Trello API testing with Postman, Circleci, Newman

  1. About PostMan and Trello
  2. Fetching the list of boards
  3. Sending a GET request
  4. Getting access to Trello API
  5. Create a board
  6. Create two lists
  7. The TODO List
  8. The DONE List
  9. Creating a card
  10. Moving the card between lists
  11. Invalid operations for cards
  12. Delete Board
  13. Run in Postman
  14. Configure folder structure
  15. Configure and commit code to GitHub
  16. Configure project in CircleCI
  17. Running scripts from CLI using Newman and view the result in CircleCI

About Postman and the Trello API

Postman is a lightweight tool the interact with Web Services. By abstracting low-level commands, such as cURL, and by structuring request formation, Postman allows us to create complex requests and explore APIs with ease.

curl --request GET --url https://api.trello.com/1/members/id/boards
Create environment global variables in postman

Getting access to Trello API

However, to create and modify entities using the Trello API, we need to identify ourselves in the HTTP requests.

Create a Board

Ok, we can access the Trello API using our keys and fetch data from it.

curl --request POST --url https://api.trello.com/1/boards/?name=name
pm.response.json().id;

Create two lists

Our board is created and we have a reference to it. It’s time to create some lists…

curl --request POST --url 'https://api.trello.com/1/lists?name=name&idBoard=idBoard'

The DONE List

The DONE list will follow the same pattern as the TODO List: All checks and procedures of the previous section can be duplicated.

Creating a card

With our lists created, we can populate them with cards.

curl --request POST --url https://api.trello.com/1/cards?idList=idList
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
pm.test(“Name to equal That’s a Bug”, function () {
const data = pm.response.json();
pm.expect(data.name).to.eql(pm.environment.get(“ThatsABugCardName”))
});
pm.test(“Created on correct list”, function () {
const data = pm.response.json();
pm.expect(data.idList).to.eql(pm.environment.get(“TODOListId”));
});
pm.test(“Created on correct board”, function () {
const data = pm.response.json();
pm.expect(data.idBoard).to.eql(pm.environment.get(“trelloBoardid”));
});

Moving the card between lists

Now that a card is created the TODO list, we will move this card to the DONE list.

curl --request PUT --url https://api.trello.com/1/cards/id

Invalid operations

Let’s say we send a move request for a card that does not exist — maybe it never existed, or another application have deleted between our creation and move requests.

Deleting the board

We have already Created, Retrieved, and Updated boards, lists and cards. Now it’s time to Delete our board.

curl --request DELETE --url https://api.trello.com/1/boards/id
After sending the request, we get 200 OK as response, with a null-like body:

Export collections from postman

Within postman from left had menu for the project click on “…” and click o Export button, and save it local disk with name “PostmanTrelloCollections.json”

Done, now lets create simple folder structure in local disk.

Create project folder as “trellopostman”, under this create folder as “tests” and then push the two collections files that already downloaded in previous step.

Push code to GitHub

Make sure you have an account and then follow the command to push. Learn more about creating git repository here — https://opensource.com/article/18/1/step-step-guide-git

sample commands 
git status
git add .git commit -m “made some changes”git push -u origin master

Lets Integrate with CircleCI

Make sure to create an account in Circleci and also the project that would point to your github account and repository.

version: 2.1orbs:newman: postman/newman@0.0.2jobs:build:executor: newman/postman-newman-dockersteps:- checkout- newman/newman-run:collection: ./tests/PostmanTrelloCollections.jsonenvironment: ./tests/TrelloEnv.json

What is NewMan

Newman is a command line Collection Runner for Postman. It allows you to run and test a Postman Collection directly from the command line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.

How to run scripts from command line

Newman allows you to run Postman test collections whenever code is pushed to your repository. Once all commit is done to Github repository as in previous step and CircleCI/config.yml configured now run “git push” from command line, this would run the scripts in CircleCI as below;

Next time

In next blog, we will build upon the tests developed with Postman BDD and also Contract Testing to run the tests on command line and CI using Newman.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gururaj Hm

Gururaj Hm

Director of Technology — Shared Services @ cipio.ai