Triggering Traces with Postman

This guide is based on Postman version 9.31.

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 "Environments" tab in the left navigation

    edit postman configuration eye icon

  2. Next select Globals

  3. Click into the "Add New Variable" input field and add tideways_apikey as the key and your Tideways API from the "General Settings" page of your project.

  4. Click Save.

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

tideways apikey set in postman configuration

Alternatively you can set different API Keys by setting the variables inside an "Environment" instead of the "Globals" of Postman.

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. The one-time hash is added as a header to the requeset automatically.

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

if (apiKey && apiKey.length > 0) {
    var crypto = require('crypto-js');
    const uuid = require('uuid');

    const time = (new Date(Date.now() + 1000*60*30).valueOf())
    const payload = 'method=&time=' + time + '&user=1';
    const hash = CryptoJS.HmacSHA256(payload, CryptoJS.MD5(apiKey).toString(CryptoJS.enc.Hex));

    pm.request.headers.add(
        "hash=" + hash.toString(CryptoJS.enc.Hex) + "&" + payload,
        "X-Tideways-Profiler"
    );
    pm.request.headers.add(uuid.v4(), "X-Tideways-Ref");
}
Still need help? Email [email protected]