How to get a list of devices using the API and Python.


Userlevel 3

The same data that can be found in the Forward Enterprise GUI can also be accessed via the API. Here is an example to pull a JSON formatted list of all the devices in a Network using the API and Python.

Start by generating an API key from Settings > Account API Tokens. You will have to re-enter your password. Write down the API password. It will not be shown again! 

 

Go to the API docs (https://fwd.app/api-doc) If you have an on-prem deployment of Forward Networks, the domain name in the URL will be specific to your company. Enter the API Access Key and Secret Key that you created.

Go to the Network Devices section of the same page (https://fwd.app/api-doc#network-devices)

Click Try it out. Note that this button will only work if you have already entered your API credentials.

 

Enter the Network ID that you want to pull a list of devices from. (This is the number in the URL when you are in the App on the search tab: fwd.app/?/settings/account?networkId=12346&snapshotId=91011)

Click Execute.

 

This will generate the Curl command that you can use in a script including the Request URL, as well as provide the actual JSON output for the command. The “name” field in the JSON snippet above are the names of the devices. The data is from the most recent snapshot of the Network ID provided.

Using the Request URL and auth string provided above, the Python code below would get the same JSON ouput.

 
import http.client

conn = http.client.HTTPSConnection("fwd.app")

headersList = {
"Accept": "*/*",
"User-Agent": "Thunder Client (https://www.thunderclient.com)",
"Authorization": "Basic **redacted**"
}

payload = ""

conn.request("GET", "/api/networks/12346/devices?skip=0", payload, headersList)
response = conn.getresponse()
result = response.read()

print(result.decode("utf-8"))

 


0 replies

Be the first to reply!

Reply