API Test: Create your first API Testing in POSTMAN

Krisnawan Hartanto
4 min readSep 26, 2022

In this article I will show how to create basic request in postman.

Basic Features

Before creating postman request, first let me show you postman basic features. I will show features like

  • Params — Allows you to add query parameter in request URL
  • Authorization — It might be basic authentication, bearer token, or just simply username and password
  • Headers — Where you will write needed header for the request
  • Body — This is where you put customization values.
  • Pre-request Script — Executed before running the request. You can add environment variables or test preconditions here.
  • Tests — This is where you put our assertion script for the test. It is important to add assertion for each request so we know whether the request is succeed or not.

Create Our Request

Now after we know Postman’s basic features, we are ready to create our first postman request. For this article’s simulation I will use demo site from dummyjson. You can access the swagger here:

For this simulation I will use endpoint “Add a new product”. This endpoint will simulate POST request and mock a create new product behavior.

Add a new product simulation
  1. Create a Collection to organize our request — Yes we can create single request without a collection, but a collection will help us to make our request more well organized. We also can group our collection into folders under the same category, such as: Setup, Positive Cases, Negative Cases, and Cleanup.
Collection creation

2. Create request — In this step we will create a request. To create a request within a collection, click triple dot from collection then Add Request. Write down Request name and Request description (Optional). Click “Save to HTTP Method”.

Request creation

3. After request is created then we are ready to make a postman request.

{
“titles”: “BMW Pencil”
}
Request body

4. Click “Send” button — After this step is executed we already get the result whether fail or success. In this simulation the request return 200 as response code and “id”: 101 as response body.

Request response

5. Test Assertion — now, after we get the response code and response body, we need to assert the test to assure endpoint returned expected response.

  • To add assertion, click “Tests” tab
  • For this simulation, create an assertion using snippets is enough. So move to snippets and choose on of them.
Test Snippets
  • I will assert this request using two snippets, ”Status code is 200" and “Response body: JSON value check”.
  • Click those snippets. Now we will have two code blocks. The first block is good enough, so we will work on the second block. String “Your test name” can be changed into any string you desire, so I will change it into “Product id is 101”. Because returned Json key is “id” and the value is 101, so we will change “pm.expect(jsonData.value).to.eql(100);” into “pm.expect(jsonData.id).to.eql(101);”
  • I think it is good enough now. Click “Send” button again.
  • In the response click “Test Results” and we will get two results ”Status code is 200" and “Product id is 101”. And both of them are PASS. Those results are from previous test block.

That’s how we create basic API test using Postman. This test is simulating positive scenario. Maybe I will write about how to create negative scenario in the next article.

Thanks for reading.

Follow me on

Facebook: https://www.facebook.com/mydoqa/

Instagram: https://www.instagram.com/mydoqa/

Twitter: https://twitter.com/MydoQa

Resources

--

--