Bird
Raised Fist0
Postmantesting~20 mins

POST request in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
POST Request Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the response status code for this POST request?
Consider this Postman test script snippet that sends a POST request to create a new user. What will be the status code in the response if the user is created successfully?
Postman
pm.test('Status code is 201', function () {
    pm.response.to.have.status(201);
});
A200
B404
C400
D201
Attempts:
2 left
💡 Hint
201 means resource created successfully.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies the JSON response contains the new user's id?
You send a POST request to create a user. The response JSON contains an 'id' field. Which Postman test assertion correctly checks that the 'id' field exists and is not null?
Apm.expect(pm.response.json().id).to.exist;
Bpm.expect(pm.response.json().id).to.be.undefined;
Cpm.expect(pm.response.json().id).to.be.null;
Dpm.expect(pm.response.json().id).to.equal('');
Attempts:
2 left
💡 Hint
The id should exist and not be null or undefined.
🧠 Conceptual
advanced
2:00remaining
What is the main purpose of using POST requests in API testing?
In API testing, why do we use POST requests instead of GET requests?
ATo create new resources or submit data to the server
BTo update existing data partially on the server
CTo retrieve data from the server without changing it
DTo delete resources from the server
Attempts:
2 left
💡 Hint
POST is used to send data to the server to create something new.
🔧 Debug
advanced
2:00remaining
Why does this Postman test fail when checking the response body?
Given this test script after a POST request, why does it fail? pm.test('Response has name', function () { pm.expect(pm.response.text()).to.include('name'); });
AThe 'name' field is missing in the response JSON
Bpm.expect cannot be used with pm.response.text()
CThe response is JSON, so pm.response.text() returns a string, not parsed JSON
DThe test syntax is incorrect and missing a semicolon
Attempts:
2 left
💡 Hint
Check if the response is parsed JSON or plain text.
❓ framework
expert
3:00remaining
Which Postman test script correctly validates a POST response with nested JSON and status 201?
You send a POST request that returns a JSON response with this structure: { "user": { "id": 123, "profile": { "email": "test@example.com" } } } Which test script correctly asserts the status is 201 and the email is 'test@example.com'?
A
pm.test('Status and email', () => {
  pm.response.to.have.status(200);
  pm.expect(pm.response.json().user.email).to.eql('test@example.com');
});
B
pm.test('Status and email', () => {
  pm.response.to.have.status(201);
  pm.expect(pm.response.json().user.profile.email).to.eql('test@example.com');
});
C
pm.test('Status and email', () => {
  pm.response.to.have.status(201);
  pm.expect(pm.response.json().profile.email).to.eql('test@example.com');
});
D
pm.test('Status and email', () => {
  pm.response.to.have.status(201);
  pm.expect(pm.response.json().user.profile.email).to.equal('wrong@example.com');
});
Attempts:
2 left
💡 Hint
Check the JSON path and status code carefully.

Practice

(1/5)
1. What is the main purpose of a POST request in API testing?
easy
A. To send data to the server to create or update a resource
B. To retrieve data from the server without changing it
C. To delete a resource from the server
D. To check the server status without sending data

Solution

  1. Step 1: Understand HTTP methods

    HTTP methods define actions: GET retrieves data, POST sends data to create or update resources.
  2. Step 2: Identify POST request purpose

    POST requests include a body with data to be processed by the server, usually creating or updating resources.
  3. Final Answer:

    To send data to the server to create or update a resource -> Option A
  4. Quick Check:

    POST = send data to create/update [OK]
Hint: POST sends data to server to create or update [OK]
Common Mistakes:
  • Confusing POST with GET which only retrieves data
  • Thinking POST deletes data instead of creating/updating
  • Assuming POST does not send a request body
2. Which of the following is the correct way to set the body of a POST request in Postman using JSON?
easy
A. Select 'Headers' tab and add JSON data as header values
B. Select 'Params' tab and enter JSON data as key-value pairs
C. Select 'Authorization' tab and paste JSON data
D. Select 'Body' tab, choose 'raw', then select 'JSON' from dropdown and enter JSON data

Solution

  1. Step 1: Locate body settings in Postman

    In Postman, the 'Body' tab is used to send data with POST requests.
  2. Step 2: Choose raw and JSON format

    Within 'Body', selecting 'raw' and then 'JSON' allows entering JSON formatted data correctly.
  3. Final Answer:

    Select 'Body' tab, choose 'raw', then select 'JSON' from dropdown and enter JSON data -> Option D
  4. Quick Check:

    Body tab + raw + JSON = correct POST body setup [OK]
Hint: Use Body > raw > JSON to send JSON data [OK]
Common Mistakes:
  • Entering JSON in Params tab which is for URL parameters
  • Putting JSON data in Headers which is for metadata
  • Confusing Authorization tab with body data input
3. Given this Postman test script for a POST request response:
pm.test('Status code is 201', () => {
  pm.response.to.have.status(201);
});
pm.test('Response has userId', () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData).to.have.property('userId');
});

What will happen if the server responds with status 200 and no userId in the JSON?
medium
A. Both tests fail because status is not 201 and userId is missing
B. First test passes, second test fails
C. Both tests pass regardless of response
D. First test fails, second test passes

Solution

  1. Step 1: Check status code test

    The first test expects status 201 but server returns 200, so this test fails.
  2. Step 2: Check userId property test

    The second test expects 'userId' property in JSON response, but it's missing, so this test also fails.
  3. Final Answer:

    Both tests fail because status is not 201 and userId is missing -> Option A
  4. Quick Check:

    Status 201 + userId present = pass; else fail [OK]
Hint: Check both status and JSON properties carefully [OK]
Common Mistakes:
  • Assuming status 200 passes when test expects 201
  • Ignoring missing JSON properties in assertions
  • Thinking tests pass without matching conditions
4. You wrote this Postman test for a POST request:
pm.test('Check success message', () => {
  pm.expect(pm.response.json().message).to.eql('Success');
});

But the test always fails with error TypeError: Cannot read property 'message' of undefined. What is the most likely cause?
medium
A. The server returned status 404
B. The test syntax is incorrect
C. Response body is empty or not valid JSON
D. The Postman app is outdated

Solution

  1. Step 1: Understand the error message

    The error means pm.response.json() returned undefined, so accessing .message fails.
  2. Step 2: Identify cause of undefined JSON

    This usually happens if response body is empty or not valid JSON, so parsing fails.
  3. Final Answer:

    Response body is empty or not valid JSON -> Option C
  4. Quick Check:

    Empty or invalid JSON causes undefined error [OK]
Hint: Check if response body is valid JSON before accessing properties [OK]
Common Mistakes:
  • Blaming test syntax instead of response content
  • Ignoring server status codes affecting response body
  • Assuming Postman app version causes this error
5. You want to test a POST request that creates a new user with fields name and email. Which Postman test script correctly verifies the server response includes the same email you sent and a status code 201?
hard
A. pm.test('Status 201 and email match', () => { pm.response.to.have.status(201); const res = pm.response.json(); pm.expect(res.email).to.eql(pm.request.body.raw.email); });
B. pm.test('Status 201 and email match', () => { pm.response.to.have.status(201); const res = pm.response.json(); const req = JSON.parse(pm.request.body.raw); pm.expect(res.email).to.eql(req.email); });
C. pm.test('Status 201 and email match', () => { pm.response.to.have.status(200); const res = pm.response.json(); pm.expect(res.email).to.eql('test@example.com'); });
D. pm.test('Status 201 and email match', () => { pm.response.to.have.status(201); pm.expect(pm.response.json().email).to.exist; });

Solution

  1. Step 1: Check status code assertion

    The test must check for status 201, which indicates resource creation.
  2. Step 2: Compare response email with request email

    Since request body is raw JSON string, parse it with JSON.parse(pm.request.body.raw) to access email for comparison.
  3. Step 3: Validate correct assertion

    pm.test('Status 201 and email match', () => { pm.response.to.have.status(201); const res = pm.response.json(); const req = JSON.parse(pm.request.body.raw); pm.expect(res.email).to.eql(req.email); }); correctly parses request body and compares res.email with req.email, ensuring they match.
  4. Final Answer:

    pm.test('Status 201 and email match', () => { pm.response.to.have.status(201); const res = pm.response.json(); const req = JSON.parse(pm.request.body.raw); pm.expect(res.email).to.eql(req.email); }); -> Option B
  5. Quick Check:

    Parse request body JSON before comparing fields [OK]
Hint: Parse request body JSON to compare fields in tests [OK]
Common Mistakes:
  • Trying to access pm.request.body.raw.email directly without parsing
  • Checking wrong status code like 200 instead of 201
  • Only checking email exists without matching request value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard