Skip to main content
Skip table of contents

Access the Armor API System via an API token - Python

You can use the API tokenization feature (Python) 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

To authenticate, you need to build a header with the following components:

Parameter

Description

app_id

Enter the Key ID generated from AMP.

secret_key

Enter the Secret Key generated from AMP.

request_path


http_method

Enter POST.

timestamp

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

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 ( : ).

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


Review sample code for Python 2.7.13 (Post Request):

CODE
def post_requests_apiKey_payload(self,  path = "/example/anywhere/", body = ):
        app_id = "<api_key_id>"
        secret_key = "<secret_key>"
        request_path = urlparse.urlparse(path).path
        http_method = "POST"
        timestamp = int(time.time())
        nonce = uuid.uuid4()
        hash_obj = hashlib.sha512(json.dumps(body)).digest()
        request_body = base64.b64encode(hash_obj)
        content = (app_id, http_method, request_path, str(nonce), str(timestamp), request_body)
        request_data = ''.join(content)
        mc = hmac.new(secret_key, request_data, hashlib.sha512)
        signature = base64.b64encode(mc.digest())
        auth_header = "ARMOR-PSK " + str(app_id) + ':' + str(signature) + ':' + str(nonce) + ':' + str(timestamp)
        request_header = {
            'Content-Type': 'application/json',
            "Authorization": auth_header
        }
        response = requests.post(self._url(path), data=json.dumps(body), headers=request_header)
        print (response.status_code)
        return response


Review sample code for Python 3.6.5 (Post Request):

CODE
def _post_requests_apiKey_payload(self, path="/example/anywhere", body = ):
        app_id = "<api_key_id>"
        secret_key = "<secret_key>"
        request_path = urlparse(path).path
        http_method = "POST"
        timestamp = int(time.time())
        nonce = uuid.uuid4()
        hash_obj = hashlib.sha512(bytes(json.dumps(body), 'utf-8'))
        request_body = base64.standard_b64encode(hash_obj.digest())
        content = (app_id, http_method, request_path, str(nonce), str(timestamp), request_body.decode())
        request_data = ''.join(content)
        mc = hmac.new(bytes(secret_key, 'utf-8'), bytes(request_data, 'utf-8'), hashlib.sha512)
        signature = base64.standard_b64encode(mc.digest())
        auth_header = "ARMOR-PSK " + str(app_id) + ':' + str(signature.decode('utf-8')) + ':' + str(
            nonce) + ':' + str(timestamp)
        request_header = {
            'Content-Type': 'application/json',
            "Authorization": auth_header
        }
        response = requests.post(self._url(path), data=json.dumps(body), headers=request_header)
        print (response.status_code)
        return response


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.