top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

End-to-End API Testing with Postman

Jun 22
4 min read

API Chaining, Data-Driven Testing, Complete Response Validation, Newman CLI Reporting, and Jenkins CI/CD Integration


API chaining in Postman is the practice of linking multiple API requests sequentially so that the data returned from one response automatically feeds into the next request. This is commonly used to extract resources like authentication tokens, newly created resource IDs, or session variables to pass along down the line.

In a simple :

Using the output of one API request as the input for another API request.

In real applications, APIs are usually dependent on each other.


Advantages of API Chaining:

API Chaining enables automation by eliminating manual data handling between requests. It supports end-to-end testing using dynamic data from API responses, reduces manual effort, improves test reliability, and simulates real-world business workflows.


What is Data-Driven Testing?

Data-Driven Testing means:

Running the same API test multiple times with different data.Instead of creating multiple requests, you use one request and multiple test datasets.

Data-Driven Testing is a technique where the same API test is executed multiple times with different input datasets from CSV or JSON files. It improves coverage, reduces script duplication, and validates APIs against multiple scenarios.

Suppose a registration API must handle:

  • Different names

  • Different languages

  • Different grades

  • Different countries

Instead of creating 100 requests, you create one for 100 test records.

API Chaining + Data-Driven Testing Together:

For each iteration:

Data-Driven Testing allows us to execute the same API test with multiple datasets stored in external files like JSON or CSV. Instead of hardcoding request payloads and expected response values, data is dynamically retrieved from these files for both request execution and response validation. This reduces script duplication, improves maintainability, and increases test coverage.



Response Validation :

Response Validation is the process of verifying that an API response contains the correct data, structure, status code, headers, and response time according to the requirements.

Response validation in Postman ensures that your API’s implementation aligns with its defined data contract and behaves reliably under different conditions. Without it, a request might return a successful 200 OK status code while delivering empty, corrupted, or broken payload structures without triggering any alerts

Checking only status codes gives limited confidence.

Checking:

  • status codes

  • response body

  • headers

  • schema

  • response time

provides comprehensive validation.

Below are some of the response validations:

//Schema validation
var schema=
   {
 "$schema": "http://json-schema.org/draft-04/schema#",
 "type": "object",
 "properties": {
   "id": {
     "type": "string"
   },
   "name": {
     "type": "string"
   },
   "grade": {
     "type": "integer"
   },
   "languages": {
     "type": "array",
     "items": [
       {
         "type": "string"
       },
       {
         "type": "string"
       }
     ]
   },
   "sports": {
     "type": "array",
     "items": [
       {
         "type": "string"
       },
       {
         "type": "string"
       }
     ]
   }
 },
 "required": [
   "id",
   "name",
   "grade",
   "languages",
   "sports"
 ]
}
const jsonData=pm.response.json()
console.log(jsonData)
pm.test("Status code is 201",()=>{
pm.response.to.have.status(201);
});
pm.test("Response time is lessthan 10ms",()=>{
pm.expect(pm.response.responseTime).to.be.below(50);
});
pm.test("Resonse code is 200 or 201",()=>{
pm.expect(pm.response.code).to.be.oneOf([200,201]);
});
//Check headers
//check content-type
pm.test("Conten-Type header is present", ()=>{
pm.response.to.have.header("Content-Type");
})
pm.test("Content-Length header is present ", ()=>{
pm.response.to.have.header("Content-Length");
})
pm.test("Content-Type header is application/json",()=>{
pm.expect(pm.response.headers.get("Content-Type")).to.equal("application/json")
})
pm.test("Content-Type header contains application/json",()=>{
pm.expect(pm.response.headers.get("Content-Type")).to.include("application/json")
})
//Check json fields
pm.test("json filed validation",()=>{
pm.expect(jsonData.name).to.eql(pm.iterationData.get("Name"))
pm.expect(jsonData.grade).to.eql(pm.iterationData.get("Grade"))
pm.expect(jsonData.languages[0]).to.eql(pm.iterationData.get("Language1"))
pm.expect(jsonData.languages[1]).to.eql(pm.iterationData.get("Language2"))
pm.expect(jsonData.sports[0]).to.eql(pm.iterationData.get("Sport1"))
pm.expect(jsonData.sports[1]).to.eql(pm.iterationData.get("Sport2"))
})
//Check value types
pm.test("Test datatypes of the response",()=>{
pm.expect(jsonData).to.be.an("object")
pm.expect(jsonData.name).to.be.a("string")
pm.expect(jsonData.grade).to.be.a("number")
pm.expect(jsonData.languages).to.be.an("array")
pm.expect(jsonData.sports).to.be.an("array")
})
pm.globals.set("userid",jsonData.id)
// Get useid from response
pm.test("Get userid from response",()=>{
pm.globals.set("userid",jsonData.id)
})
// Set the next request in the API chain
pm.execution.setNextRequest("update_stud")

After creating all the required API requests, execute the collection by supplying a JSON or CSV data file. This enables data-driven testing and helps validate both successful and failed test scenarios across multiple datasets.




What is Newman CLI?

Newman is the Command Line Interface (CLI) tool for Postman that allows Postman collections to be executed from the command line. It is used for API test automation, data-driven testing, report generation, and integration with CI/CD tools such as Jenkins. Newman enables automated execution of API tests without requiring the Postman application and is widely used in continuous testing pipelines.


Why do we use Newman?

Postman is great for creating and testing APIs manually, but in real projects we need automation.

Newman helps us:

  • Run Postman collections from the terminal

  • Execute data-driven tests using JSON or CSV files

  • Generate test reports (HTML, JSON, JUnit, etc.)

  • Integrate API tests with CI/CD tools like Jenkins

  • Schedule automated test execution

  • Run tests in build and deployment pipelines


These commands install Newman and the HTML Extra Reporter globally on your system.

npm install -g newmannpm install -g newman-reporter-htmlextra

After exporting the Postman collection and global variables, the collection can be executed outside of Postman using Newman CLI. By providing the collection file, test data file (JSON/CSV), and global variables file, Newman executes the API tests from the command line and generates a detailed HTML report for test analysis.

newman run postman_collection.json -d data_file.json -g postman_globals.json -r cli,htmlextra /- reporter-htmlextra-export report.html

This command runs the Postman collection, performs data-driven testing using the JSON data file, applies the global variables, displays the execution results in the terminal, and generates a detailed HTML report named report.html.




What is Jenkins CI/CD?

Jenkins is an open-source automation server used to implement CI/CD pipelines. In Continuous Integration (CI), Jenkins automatically builds and tests applications whenever code changes are committed. In Continuous Delivery/Deployment (CD), Jenkins automates the release and deployment process. In API testing, Jenkins is commonly integrated with Newman to execute Postman collections, generate reports, and provide continuous feedback on API quality.


Why Use Jenkins with Newman?

Automation

No need to manually run Postman collections.

Scheduled Execution

Tests can run:

  • Every hour

  • Every day

  • Every code commit

Continuous Testing

API tests run automatically whenever code changes are pushed.

Reporting

Jenkins can publish:

  • Newman HTML reports

  • Test results

  • Build history

Team Visibility

Everyone can see:

  • Build status

  • Test results

  • Failed test cases

In your project:




To build and run a Jenkins job for API testing, we need to configure Node.js (for executing Newman), Git (for source code integration), and the HTML Publisher plugin (for generating and displaying test reports). We also integrate the GitHub repository and provide Newman CLI commands to execute collections and generate reports.

CI/CD Jenkins command:

newman run postman_collection.json \-d data_file.json \-g postman_globals.json \-r cli,htmlextra \- reporter-htmlextra-export results/report.html




Thanks and Regards.

 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page