We use the Send request block to make a call to a web service or API. It helps us check if the service works correctly by sending data and getting a response.
When you want to test if a website or app API returns the right data.
When you need to check if a server accepts your data and responds properly.
When you want to automate sending requests to an API during testing.
When you want to verify the status code and response time of an API.
When you want to test different inputs and see how the API reacts.
But the request is not sent. What is the likely problem?
medium
A. Incorrect HTTP method; POST is not allowed
B. Missing callback function to handle the response
C. Body should be sent as form-data, not raw JSON
D. URL is invalid and causes failure
Solution
Step 1: Check the sendRequest syntax
pm.sendRequest requires a callback function as the second argument to execute the request properly.
Step 2: Identify missing callback
The script lacks the callback function, so the request is not sent or handled.
Final Answer:
Missing callback function to handle the response -> Option B
Quick Check:
sendRequest needs callback to send request [OK]
Hint: Always include callback function in pm.sendRequest [OK]
Common Mistakes:
Ignoring the need for callback function
Assuming HTTP method is wrong without checking API docs
Thinking body format is always wrong
Blaming URL without testing it
5. You want to send a POST request with JSON data and verify the response contains a field success set to true. Which Postman script correctly sends the request and tests the response?
hard
A. pm.sendRequest({url: 'https://api.example.com/save', method: 'POST', body: {data: 123}}, function (err, res) { pm.test('Success is true', () => { pm.expect(res.success).to.be.true; }); });
B. pm.sendRequest('https://api.example.com/save', 'POST', {data: 123}, function (err, res) { pm.expect(res.success).to.equal(true); });
C. pm.sendRequest({url: 'https://api.example.com/save', method: 'POST', header: {'Content-Type': 'application/json'}, body: {mode: 'raw', raw: JSON.stringify({data: 123})}}, function (err, res) { pm.test('Success is true', () => { pm.expect(res.json().success).to.be.true; }); });
D. pm.sendRequest({url: 'https://api.example.com/save', method: 'POST', body: {mode: 'formdata', formdata: {data: 123}}}, function (err, res) { pm.test('Success is true', () => { pm.expect(res.json().success).to.be.true; }); });
Solution
Step 1: Check request format for JSON POST
The correct script sets Content-Type header to application/json and sends body as raw JSON string.
Step 2: Verify response test syntax
The correct script uses res.json() to parse response and checks success field is true with valid assertion.
Step 3: Compare other options
The incorrect options use wrong argument formats, miss headers, or send formdata instead of raw JSON.
Final Answer:
pm.sendRequest({url: 'https://api.example.com/save', method: 'POST', header: {'Content-Type': 'application/json'}, body: {mode: 'raw', raw: JSON.stringify({data: 123})}}, function (err, res) { pm.test('Success is true', () => { pm.expect(res.json().success).to.be.true; }); }); -> Option C
Quick Check:
JSON POST: header + raw body + res.json().success [OK]
Hint: Set JSON header and use res.json() to test response [OK]
Common Mistakes:
Omitting Content-Type header for JSON
Sending body as plain object without raw string
Using wrong argument order in sendRequest
Testing response without parsing JSON
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.