Skip to main content
Skip table of contents

Access the Armor API System via an API token - Postman and JavaScript

You can use the API tokenization feature (Postman and Javascript) in the Armor Management Portal (AMP) to create an API key. This key will help you log into the Armor API system.


Step 1: Create an API key

When you create an API Key, you will generate a Secret Key. This key does not expire; you must securely store this key because Armor cannot retrieve this key for you. 

If you lose the Secret Key, then you must delete the corresponding API Key in AMP. Afterwards, you must create a new API Key.

Armor cannot retrieve your Secret Key.

  1. In the Armor Management Portal (AMP), in the left-side navigation, click Account

  2. Click Users

  3. Click API Keys

  4. Click the plus icon. 

  5. Enter a descriptive name, and then click Create Key

  6. Copy the Key ID and Secret Key

  7. Click Close

  8. The API Keys table will display a new entry.


Step 2: Authenticate into the Armor API system

  1. In your Postman application, create a new GET request with the following endpoint: https://api.armor.com/roles

  2. Click Headers.

  3. Under Key, select Authorization.

  4. In Value, enter {{hmacAuthHeader}}.

  5. Under Key, select Content-Type.

  6. In Value, enter application/json.

  7. Click Pre-request Script.

  8. Enter the script below with the following updated parameters:

Parameter

Description

APP_ID

Enter the Key ID generated from AMP.

In the example below, replace <use the api key id> with your key ID.

SECRET_KEY

Enter the Secret Key generated from AMP.

In the example below, replace <use the secret key> with your secret key.

nonce

Enter a unique ID.

  • This ID should be unique per request.

  • This ID cannot be longer than 128 characters.

  • This ID cannot contain a colon ( : ).

timestamp

Enter a Unix time stamp within 5 minutes of the current time.

For all v2 API's, the request body should be empty.

CODE
function getPath(url) {
    var pathRegex = /.+?\:\/\/.+?(\/.+?)(?:#|\?|$)/;
    var result = url.match(pathRegex);
    return result && result.length > 1 ? result[1] : '';
}
  
function getQueryString(url) {
    var arrSplit = url.split('?');
    return arrSplit.length > 1 ? url.substring(url.indexOf('?')+1) : '';
}
  
function getAuthHeader(httpMethod, requestUrl, requestBody) {
    *var APP_ID = '<use the api key id>';*
    *var SECRET_KEY = '<use the secret key>';*
    var AUTH_TYPE = 'ARMOR-PSK';
    var requestPath = getPath(requestUrl).replace('https', 'http');
    var queryString = getQueryString(requestUrl);
    if (httpMethod == 'GET' || !requestBody) {
        requestBody = '';
    } else {
        requestBody = requestBody.toString();
        requestBody = CryptoJS.enc.Base64.stringify(CryptoJS.SHA512(requestBody));
    }  
    var timestamp = Math.round(new Date().getTime() / 1000);
    var nonce = timestamp;
    var requestData = [APP_ID, httpMethod, requestPath, nonce, timestamp, requestBody].join("");
    var mac = CryptoJS.HmacSHA512(requestData, SECRET_KEY);
    var signature = CryptoJS.enc.Base64.stringify(mac);
    var authHeader = AUTH_TYPE + ' ' + APP_ID + ':' + signature + ':' + nonce + ':' + timestamp;
    return authHeader;
}
postman.setEnvironmentVariable('hmacAuthHeader', getAuthHeader(request['method'], request['url'], request['data']));


Step 3: Make an API Call

To learn about the different calls that you can make, see Armor API Guide.


Related Documentation




JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.