Forum Discussion
Anonymous
2 years agoThe code should look like this:
// Get API credentials from environment variablesvar api_id = pm.environment.get('api_id');var api_key = pm.environment.get('api_key');
// Get the HTTP method from the requestvar http_verb = request.method;
// Extract the resource path from the request URLvar resource_path = request.url.replace(/(^{{url}})([^\?]+)(\?.*)?/, '$2');
// Get the current time in epoch formatvar epoch = (new Date()).getTime();
// If the request includes a payload, included it in the request variablesvar request_vars = (http_verb == 'GET'||http_verb == 'DELETE') ?http_verb + epoch + resource_path : http_verb + epoch + request.data + resource_path;
// Generate the signature and build the Auth headervar signature = btoa(CryptoJS.HmacSHA256(request_vars,api_key).toString());var auth = "LMv1 " + api_id + ":" + signature + ":" + epoch;
// Write the Auth header to the environment variablepm.environment.set('auth', auth);
Related Content
- 2 years ago
- 7 months ago