API Keys

You can use the PacketFabric public REST API to develop projects and applications.

To interact with PacketFabric services through the API, you need some form of authentication. You have two options:

  • Session token and cookie
  • API key and hash

If you are planning on using the portal while simultaneously running automated API calls, you should authenticate with an API key.

The session token only supports one authenticated session at a time, therefore running automated API calls will interfere with your ability to use the portal.

To generate an API key:

  1. Log in to the PacketFabric portal.

  2. Click Admin.

    alt_text

  3. Under Manage, select API Keys.

  4. From the drop-down menu at the top, select a user.

  5. Click Generate Key for User.

The selected user is assigned a key ID and key secret.

Key ID

The key ID is transmitted with all of your calls in the api_key parameter.

alt_text

Key Secret

The key secret is never transmitted with the API.

Instead, you use the key secret to generate the auth_hash parameter.

import urllib.parse
import hashlib
import hmac
import base64

import requests
import pprint

pp = pprint.PrettyPrinter(indent=2)

api_key = '1-0123456789ABCDEF'
api_secret_key = '0123456789ABCDEF0123456789ABCDEF'
query_string = 'api_key=' + api_key

_hash = hmac.new(api_secret_key.encode(), query_string.encode(), hashlib.sha256).digest()
_hash = base64.b64encode(_hash)
_hash = urllib.parse.quote(_hash)

url = 'https://api.packetfabric.com/interfaces/physical?{}&auth_hash={}'.format(query_string, _hash)

print(url)

resp = requests.get(url)

pp.pprint(resp.json())