Asynchronous requests with Postman's PM API

0

Category : , , ,

You can send requests asynchronously with the pm API method sendRequest, these can be used in the pre-request or the test script.

Its important to note that if you send an asynch request in the pre-request tab "The main Postman request will NOT be sent until the pre-request script is determined to be finished with all callbacks, including sendRequest."

A blog post containing more detailed info on this can be seen on the below link:
http://blog.getpostman.com/2017/10/03/send-asynchronous-requests-with-postmans-pm-api/

I have only done basic testing with this but I could get the method to fire using the 2nd example of the 3 available on the previous url:
var headers = ['reseller_id:' + environment.booking_api_reseller_id];
    headers.push('request_id:'+ environment.booking_api_request_id);
    headers.push('request_authentication:'+ environment.booking_api_request_authentication);
console.log(headers);

// Example with a full fledged SDK Request
const echoPostRequest = {
  url: environment.booking_api_host + '/v1/Availability/product/' + environment.booking_api_availability_productKey + '?fromDateTime=' + environment.booking_api_availability_start_date + 
        '&toDateTime=' + environment.booking_api_availability_end_date,
  method: 'GET',
  header: headers,
  body: {
    mode: 'raw',
    raw: JSON.stringify({ key: 'this is json' })
  }
};

pm.sendRequest(echoPostRequest, function (err, res) {
    console.log('..............here........');
    console.log(err ? err : res.json());
});

I was having issues passing the headers to the request but i found the below url which states the header param should be an array.
http://www.postmanlabs.com/postman-collection/Request.html#~definition

0 comments:

Post a Comment