0
0
Postmantesting~15 mins

PUT request in Postman - Build an Automation Script

Choose your learning style9 modes available
Update user information using PUT request
Preconditions (2)
Step 1: Open Postman application
Step 2: Set HTTP method to PUT
Step 3: Enter URL https://api.example.com/users/123
Step 4: In the Body tab, select raw and JSON format
Step 5: Enter JSON payload: {"name": "John Doe", "email": "john.doe@example.com"}
Step 6: Click Send button
✅ Expected Result: Response status code is 200 OK and response body contains updated user information with name 'John Doe' and email 'john.doe@example.com'
Automation Requirements - Postman Test Scripts
Assertions Needed:
Verify response status code is 200
Verify response body contains updated name 'John Doe'
Verify response body contains updated email 'john.doe@example.com'
Best Practices:
Use environment variables for base URL and user ID
Use JSON schema validation for response body
Write clear and concise test assertions
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

const responseJson = pm.response.json();
pm.test('Response has updated name', function () {
    pm.expect(responseJson.name).to.eql('John Doe');
});

pm.test('Response has updated email', function () {
    pm.expect(responseJson.email).to.eql('john.doe@example.com');
});

The first test checks that the HTTP status code returned is 200, which means the update was successful.

Then, the response body is parsed as JSON to access its properties.

Next, two tests verify that the 'name' and 'email' fields in the response match the updated values sent in the PUT request.

This ensures the API correctly updated the user information.

Common Mistakes - 4 Pitfalls
Not setting HTTP method to PUT
{'mistake': 'Sending payload in incorrect format (e.g., form-data instead of raw JSON)', 'why_bad': 'API expects JSON payload; wrong format causes server to reject or ignore data.', 'correct_approach': "Select 'raw' and 'JSON' in the Body tab and send properly formatted JSON."}
Hardcoding URL instead of using environment variables
Not validating response body content
Bonus Challenge

Now add data-driven testing with 3 different user updates using Postman Collection Runner

Show Hint