Metadata as included in the network list (INVENTORY/NETWORKS/List) can be retrieved via the REST API using the networks resource.
Follow along with our Postman Collection
To access the requests associated with the Networks endpoint, click on the Network Metadata folder in our Postman collection.
Retrieve the full network list
Retrieve all entries in the network list.
Request:
API Request
Python
Request:
GET ot-base/api/v1/networks
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1) between the quotes.
hostname = 'enterHostnameOrIP'
# Replace username and password with your username and password credentials.
auth=('username', 'password')
url = 'https://'+hostname+'/ot-base/api/v1/networks/'
response = requests.get(url,auth=auth)
print(response.status_code)
print(response.text)
Response:
Note: The output is paged in order to prevent client overflow. The info element at the end of the output will inform you about the total number of entries, and the offset for the next page.
You can then use the offset value for the next call, which is specified as followed.
Request:
API Request
Python
Request:
GET ot-base/api/v1/networks/?offset=enterOffsetAmount
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1) between the quotes.
hostname = 'enterHostnameOrIP'
# Replace username and password with your username and password credentials.
auth=('username', 'password')
url = 'https://'+hostname+'/ot-base/api/v1/networks/'
params = { 'offset': 100}
response = requests.get(url,auth=auth, params=params)
print(response.status_code)
print(response.text)
Retrieve metadata for a particular network
Retrieve metadata for the network that is identified as a sub-resource.
Note: The network IDs are auto-generated by OTbase and cannot be changed by the user.
Request:
API Request
Python
Request:
GET ot-base/api/v1/networks/networkID
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1) between the quotes.
hostname = 'enterHostnameOrIP'
# Replace username and password with your username and password credentials.
auth=('username', 'password')
# Replace enterNetworkID with a network id between the qoutes.
networkID = 'enterNetworkID'
url = 'https://'+hostname+'/ot-base/api/v1/networks/'+networkID
response = requests.get(url,auth=auth)
print(response.status_code)
print(response.text)
Updating network metadata
The following metadata can be updated via the REST API:
name
group
description
You can update metadata for a particular network by using a POST request that references the network by its network ID. For example, to change the network name of a network with the network ID of "NW.55" to "My new network name", use the following POST command
Note: Network IDs always starts with "NW." and are case sensitive.
Request:
API Request
Python
Request:
POST ot-base/api/v1/networks/NW.55
Request Body:
{ "name": "My new network name" }
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1) between the quotes.
hostname = 'enterHostnameOrIP'
# Replace username and password with your username and password credentials.
auth=('username', 'password')
# Replace enterNetworkID with a network id between the qoutes.
networkID = 'enterNetworkID'
url = 'https://'+hostname+'/ot-base/api/v1/networks/'+networkID
data ={
'name': 'enterNetworkName'
}
response = requests.post(url, json=data,auth=auth)
print(response.status_code)
print(response.text)
Comments
0 comments
Please sign in to leave a comment.