In OTbase version 6.05, we've added new feature that allows users to perform bulk edits to device metadata using the familiar /devices
endpoint or by spreadsheet upload. This new feature makes it easier for users to update device metadata in bulk using either the deviceId
or the device name
.
Bulk Update Devices Metadata by ID
To update device metadata by device ID, you must send a POST request to the /devices
endpoint. Since we are updating multiple devices, the request body will be comprised of a list of device objects. Here, we will be referencing each device by its device ID along with the metadata field that we wish to change.
API Request
Python Code
Request:
POST ot-base/api/v1/devices
Request Body:
[
{"deviceId": "{{enterDeviceID1}}","description": "{{enterDescription1}}"},
{"deviceId": "{{enterDeviceID3}}","description": "{{enterDescription2}}"},
{"deviceId": "{{enterDeviceID2}}","description": "{{enterDescription3}}"},
...
]
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1)
hostname = 'enterHostnameOrIP'
url = "https://"+hostaddres+"/ot-base/api/v1/devices/"
auth = ("username", "password") # replace with actual username and password
data = [
{"deviceId": "{{enterDeviceID1}}","description": "{{enterDescription1}}"},
{"deviceId": "{{enterDeviceID3}}","description": "{{enterDescription2}}"},
{"deviceId": "{{enterDeviceID2}}","description": "{{enterDescription3}}"},
# add more devices as needed
]
response = requests.post(url, json=(data), auth=auth, verify = False)
print(response.text)
The example request body shows how to update the description metadata for multiple devices by referencing their device IDs. Just replace {{enterDeviceID}}
and {{enterDescription}}
placeholders with the actual device ID and description respectively.
Bulk Update Devices Metadata by Name
We've also added the feature to update device metadata using the device name as it maybe easier to remember than the device id. To update device metadata using the device name, the setup will be the same like in the prior section. Only this time, we'll refer to each device by name followed by the metadata that we wish to change.
API Request
Python Code
Request:
POST ot-base/api/v1/devices
Request Body:
[
{"name":"{{enterDeviceName1}}","description": "{{Description1}}" },
{"name":"{{enterDeviceName2}}","description": "{{Description2}}" },
{"name":"{{enterDeviceName3}}","description": "{{Description3}}" },
...
]
The example request body shows how to update the description metadata for multiple devices by referencing their device names. All you need to do here is replace the {{enterDeviceName}}
and{{Description}}
with the actual device name and description respectively.
import requests
# Enter your hostname (for example: myserver.com or 127.0.0.1)
hostname = 'enterHostnameOrIP'
url = "https://"+hostname+"/ot-base/api/v1/devices/"
auth = ("username", "password") # replace with actual username and password
data = [
{"name": "{{enterDeviceName1}}", "description": "{{Description1}}"},
{"name": "{{enterDeviceName2}}", "description": "{{Description2}}"},
{"name": "{{enterDeviceName3}}", "description": "{{Description3}}"},
# add more devices as needed
]
response = requests.post(url, json=(data), auth=auth, verify = False)
print(response.text)
Comments
0 comments
Please sign in to leave a comment.