Postman & HMAC Workflow

Hi all,

First of all, festive greetings. I keep tabs on the forums and it’s a wonderful community.

Using Knime, I’m hopeful of replicating some functionality that is used in Postman.

Firstly, I’ve been provided with a Pre-request script that creates a hash - do you think this can be replicated in Knime?

// CryptoJS library
var CryptoJS = require(“crypto-js”);
// Request
var method = request.method;
var uri = request.url;
var contentType = request.headers[“content-type”];
var dt = new Date().toUTCString();
var requestData = method + uri + contentType + dt;
// HMAC
var apikey = request.headers[“apikey”];
var hash = CryptoJS.HmacSHA256(requestData, apikey);
var signature = CryptoJS.enc.Base64.stringify(hash);
// Set Headers
postman.setEnvironmentVariable(“X-anonymised-API-DATE”,dt);
postman.setEnvironmentVariable(“X-anonymised-API-SIGNATURE”,signature);

The second challenge is to use the headers created above in the GET / POST nodes…

Thank you to anybody able and willing to guide me here.

Cheers all.

John.

1 Like

Hi @Unlockedata,

attached an exmaple to calculate the HMAC in the java snippet
(using the example from java - HMAC-SHA256 Algorithm for signature calculation - Stack Overflow)

KNIME_project28.knwf (6.4 KB)

But you could also check if the Palladian Nodes provide the same as well:

For the pre-request extraction you can use the XPath and JSON Path Nodes:

For the header variables you can just go the the “Request Headers” tab of the Post/Get Nodes - here you can select if you want to set the header with a constant value or with flow variables/columns.

Hope this helps :slight_smile:

9 Likes

AFU, thank you. I’m on festive holidays - but will take a look in a few days. Thanks for taking the time…

All the best.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.