Step by step testing with postman :: Part 1

We will automate the following API’s:

Create Workspace

From workspace menu, click on “New Workspace” and give workspace name.

Click on Create workspace button. You will see new workspace has been created and showing on workspace list.

Create Collection:

Select workspace from list.

Click on the “Create Collection” button.

Give the collection name and press enter.

Add Request:

Click on “Add a request” link or right click on the collection and Click on Add request menu.

Give the request name as Customer Login


Now Enter request URL as:

Select the HTTP request method from GET to POST

Now go to Body tab

Select radio button as raw and you will see a script writing panel has opened.

Write this json to the script:


Now go to headers and add this in header:

KEY: Content-Type
VALUE: application/json

Now click on Send button and you will see that you will get a token in the response

Create environment variable:

Click on the eye icon

Click on “Add” button and give Environment name as “Customer API Env”

Now set VARIABLE as baseUrl and INITIAL VALUE as

You will see that CURRENT VALUE will be set automatically after you set INITIAL VALUE

Now go to the collection again and replace the base url “” with {{baseUrl}}.

Important note: When you save something in an environment variable, then while using it, you have to put the variable name within a curly bracket.

Then, you will see the {{baseUrl}} color gets orange. If the color is not orange, there some spelling mistake or you don’t set the environment from the environment list.

So don’t forget to set the environment from the environment list.

When you will mouse hover over the {{baseUrl}}, then you will see showing the link you just set the link tho the environment variable.

Now click on save button.

Now again click on Send button and you will see the same result is showing on response.

If not, read the article again and try to find the error.

Now go to Tests tab and copy paste following code:

var jsonData = pm.response.json();
pm.environment.set("token", jsonData.token);

This code means, the response we have saved in a variable named jsonData and then retrieve token from jsonData response and set to the environment named as “token”. Now click on Send button.

After clicking on send button, token will generate and set to the environment variable.

Calling GET API using Authentication:

Create another request named as “Customer List”

Now add this URL to the request URL field


Make sure, HTTP method is selected as “GET”

Now go to Headers tab

Set KEY as Authorization and VALUE as {{token}}

Now click on Send button

You will see response will be shown.

Now got to Tests tab and add following lines:

pm.test("Check customer data", function () {
    var response = pm.response.json();

These code means, if the customer id 101 has been matched with 101, then expected result is passed. Otherwise failed.

If you failed to set Authorization, then following response will found:

Get API response by parameter

Add another GET request.

Set URL as: {{baseUrl}}/customer/api/v1/get/101

Set HTTP request method as: GET

Click on Send button

You will get following response:

    "id": 101,
    "name": "Mr. Kamal",
    "email": "",
    "address": "Gulshan,Dhaka",
    "phone_number": "01502020110"

POST API to register new customer

Now create another request named as: “Add new customer”

Set HTTP request as POST

Set URL as {{baseUrl}}/customer/api/v1/create

Got to body tab and select radio button raw

Add following json in the script:

    "address":"Gulshan, Dhaka",

Now go to pre-requsite script and add following codes:

let id=_.random(1000, 9999)
pm.environment.set("id",id );
const reqObject = {
  url: '',
  method: 'GET',
  header: 'Content-Type:application/json'

pm.sendRequest(reqObject, (err, res) => {
    let {name} = res.json()
    let {phone_w}=res.json()
    let {email_u} = res.json()
    let email=email_u+''
    pm.environment.set("name", name);
    pm.environment.set("email", email);
    pm.environment.set("phone_number", phone_w);

This code actually calling an API to generate some user info like id, name, phone_number, and email and set to env variables.

Now go to Tests tab and add following lines:

pm.test("Status code is 201", function () {;

These code means that, while any customer registered newly, then the response code will be 201

Calling PUT API

Like as PUT API, create new request named as “Update customer”

Set HTTP method as PUT

Set URL as {{baseUrl}}/customer/api/v1/update/{{id}}

Write following json to body:

    "name":"Rahim Uddin",
    "address":"Gulshan, Dhaka",

Now click on Send button

You will get following response:


Like GET API, create another request named as “Delete customer”

set HTTP method as: DELETE

set URL as : {{baseUrl}}/customer/api/v1/delete/{{id}}

Click on send button.

You will see that the latest customer has been deleted and you will get following response:

Finally you will see that you have created following API collection:

about author


If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *