Complete the code to set the HTTP method to POST in the request block.
pm.sendRequest({ method: '[1]', url: 'https://api.example.com/data' }, function (err, res) { console.log(res); });The method property defines the HTTP method. To send data, we use POST.
Complete the code to set the request URL correctly.
pm.sendRequest({ method: 'POST', url: '[1]' }, function (err, res) { console.log(res); });The URL must be a full valid URL including the protocol https://.
Fix the error in the headers object to set Content-Type to application/json.
pm.sendRequest({ method: 'POST', url: 'https://api.example.com/data', headers: { '[1]': 'application/json' } }, function (err, res) { console.log(res); });The header key must be Content-Type with exact casing for the server to recognize it.
Fill both blanks to send JSON data with a POST request.
pm.sendRequest({ method: 'POST', url: 'https://api.example.com/data', headers: { 'Content-Type': '[1]' }, body: { [2]: JSON.stringify({ name: 'John', age: 30 }) } }, function (err, res) { console.log(res); });The header must be application/json to indicate JSON data. The body type should be raw to send raw JSON string.
Fill all three blanks to handle the response status and log success or error.
pm.sendRequest({ method: 'POST', url: 'https://api.example.com/data', headers: { 'Content-Type': 'application/json' }, body: { raw: JSON.stringify({ name: 'John' }) } }, function (err, res) { if (res.statusCode [1] 200) { console.log('[2]'); } else { console.log('[3]'); } });Use === to check if status code is 200 (OK). Log 'Success' if true, otherwise log 'Error'.