For API background including full documentation, refer to this article.
The first step in using the Lighthouse or Console Server API is to authenticate using a local or remote Opengear username and password, and obtain a session token. In the examples below, we use the factory default credentials of: root / default
This token is then passed via the headers to authenticate subsequent requests. Note that the token will expire using the timeout set for the Web UI.
Examples are provided for the cURL CLI tool, Python scripting environment, and Postman API utility.
cURL
Run this command from any system with curl installed, e.g. a Linux box, Mac, or the Opengear CLI:
curl -c /dev/null -s -k -L https://address.of.opengear/api/v2/sessions -d '{"username":"root","password":"default"}'
Copy the returned session token:
{"state":"authenticated","session":"941c07448c57e0360fe1ac35e9a5be83","user":"root"}
Now you can send subsequent requests (e.g. a GET request to https://address.of.opengear/api/v2/serialPorts/ for Console Servers, or https://address.of.opengear/api/v2/nodes/ for Lighthouse) setting your token in the headers:
curl -k -L -H 'Authorization: Token 941c07448c57e0360fe1ac35e9a5be83' https://address.of.opengear/api/v2/serialPorts/
Python
From any system with Python and the Requests libraries installed, start the Python interpreter or create a script and run:
import requests, json data = { 'username' : 'root', 'password' : 'default' } r = requests.post('https://address.of.opengear/api/v2/sessions/', data=json.dumps(data), verify=False) token = json.loads(r.text)['session']
Now you can send subsequent requests (e.g. a GET request to https://address.of.opengear/api/v1/serialPorts/ for Console Servers, or https://address.of.opengear/api/v1/nodes/ for Lighthouse) setting your token in the headers:
headers = { 'Authorization' : 'Token ' + token } r = requests.get('https://address.of.opengear/api/v2/serialPorts/', headers=headers, verify=False) j = json.loads(r.text)
print(json.dumps(j, indent=4))
Postman
Start the Postman UI utility and create a new POST request to https://address.of.opengear/api/v2/sessions/ with the Body set to:
{ "username": "root", "password": "default" }
Click Send and extract the session token from the returned Body, e.g.: 941c07448c57e0360fe1ac35e9a5be8Now you can create subsequent requests (e.g. a GET request to https://address.of.opengear/api/v2/serialPorts/ for Console Servers, or https://address.of.opengear/api/v2/nodes/ for Lighthouse) setting your token in the Headers:
Key | Value |
---|---|
Authorization | Token 941c07448c57e0360fe1ac35e9a5be83 |
Click Send.
Comments
0 comments
Article is closed for comments.