Verify API accepts correct JSON body format
Preconditions (3)
✅ Expected Result: The API responds with status code 200 and a success message indicating the body format was accepted
pm.test('Status code is 200', function () { pm.response.to.have.status(200); }); pm.test('Response has success message', function () { const jsonData = pm.response.json(); pm.expect(jsonData.message).to.eql('Login successful'); });
The first test checks that the API returns a 200 status code, meaning the request was successful.
The second test parses the JSON response and verifies that the 'message' field equals 'Login successful', confirming the API accepted the body format.
Using pm.response and pm.expect ensures we use Postman's built-in assertion methods for clarity and reliability.
Now add data-driven testing with 3 different sets of username and password combinations
Content-Type header with the body format in an API request?Content-Type header tells the API what format the request body is in, like JSON or XML.{
"name": "Alice",
"age": 30
}Content-Type: application/json, what will the API most likely do if it expects JSON?name=Bob&age=25
Content-Type: application/json. The API returns a 400 Bad Request error. What is the likely cause?{
"user": {
"name": "Eve",
"details": {
"age": 28,
"city": "NY"
}
}
}Pass the test and this pattern moves unknown