Triggering Traces with Postman

This guide is based on Postman version 4.7.2.

Postman is a widely used REST API development console, that provides support for reusable scripts to enhance its functionality. You can integrate it with Tideways Trace Triggering to get traces for every Postman request that you send. This guide shows how to do so.

1. Configure Environment

You first need to set the Tideways API key as a variable in either the Postman environment which you are using, or in its global environment.

To do this:

  1. Click the eye icon, near the top right-hand corner of the main Postman window

    edit postman configuration eye icon

  2. Next to Global, click Edit, to open up the global environment configuration window

  3. Click Bulk Edit, and add tideways_apikey as the key and your Tideways API key as the value, separated by a colon

    add tideways apikey to postman configuration

  4. Click Save.

When completed, the configuration should look similar to the screenshot below.

tideways apikey set in postman configuration

2. Set Pre-Request Script for Collection

Next, change the collection that you want to run the Tideways Profiler, to include a pre-request script, as described in Postman documentation, similar to the example below. The script uses the API Key to create a one-time, encrypted hash, triggering the Profiler.

var apiKey = pm.environment.get("tideways_apikey");

if (apiKey && apiKey.length > 0) {
  var crypto = require('crypto-js');
  var time = (new Date(Date.now() + 1000*60*5).valueOf())
  var payload = 'method=&time=' + time + '&user=';
  var hash = CryptoJS.HmacSHA256(
    payload,
    CryptoJS.MD5(apiKey).toString(CryptoJS.enc.Hex)
  );

  pm.environment.set(
    "tideways_hash",
    "hash=" + hash.toString(CryptoJS.enc.Hex) + "&" + payload
  );
}

3. Configure the Request Headers to use Tideways Profiling Hash

Sadly, pre-request scripts cannot, currently, modify the request themselves in Postman (there is an open bug / feature request). This means that you need to take one further step, and in the headers tab of the request configure the Header X-Tideways-Profiler to take on the value {{tideways_hash}} as shown in the following screenshot.

image
Still need help? Email [email protected]