Postman

How to set up the authentication in Postman?

  1. You need to set two variables to your environment clientKeyand clientSecretcontaining the two API Keys (How to create the API Keys?)

  2. Set the following header to the request:

    The variables hmacTimestamp and hmacSignature are generated on the fly by the following Pre-request script.

  3. Copy this script to the “Pre-request Script” Tab of the request (or of the collection):

    const crypto = require('crypto-js');
         
    // Helper
    function interpolate (str) {
        return str.replace(/{{([^}]+)}}/g, function (match, $1) {
            return pm.variables.get($1);
        });
    }
         
    var url = interpolate(pm.request.url.toString()),
        clientKey = pm.variables.get("clientKey"),
        clientSecret = pm.variables.get("clientSecret"),
        timestamp = Math.floor(Date.now() / 1000),
        method = pm.request.method
        body = pm.request.body ? pm.request.body.toString() : "";
             
    var signPayload = [method, url, body, timestamp],
        signature = crypto.HmacSHA256(signPayload.join("\n"), clientSecret).toString()
         
    pm.variables.set("hmacTimestamp", timestamp);
    pm.variables.set("hmacSignature", signature);