With our API, you can retrieve a list of all locations in the repository, including sub-locations, by simply making a GET request to the locations resource. Additionally, you can retrieve data for a single location by addressing the location as a sub-resource of the locations resource, using the location's unique ID. Not only can you retrieve location data, but you also have the ability to update and create new locations by making a POST request to the locations resource, using the location's unique ID.
Follow along with our Postman Collection
To access the requests associated with the Location endpoint, click on the Location data folder in our Postman collection.
Retrieve the location repository
Returns a list with all locations in the location repository, including sub-locations.
API Request
Python
Request:
GET ot-base/api/v1/locations
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/locations'
response = requests.get(url, auth=auth)
print(response.status_code)
print(response.text)
Retrieving location data for a single location
Data for a particular location can be retrieved by addressing the location id as a sub-resource of the locations endpoint.
Note: You can only use location IDs, but not hierarchical location names, to address a location.
API Request
Python
Request:
GET ot-base/api/v1/locations/locationId
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 enterLocation with a location id defined in your Asset Center.
locationID = 'enterLocationID'
url = 'https://'+hostname+'/ot-base/api/v1/locations/'+locationID
response = requests.get(url, auth=auth)
print(response.status_code)
print(response.text)
Updating location data, and creating a new location
Data for a particular location can be updated with a POST command.
If the location ID supplied with the command doesn't exist, a new location is created with the name assigned in the body of the request.
API Request
Python
Request:
POST ot-base/api/v1/locations/JA
Request Body:
{ "name":"Jamaica", "company":"Foreign Associates" }
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')
# Enter a device id between the quotes.
deviceID = 'enterDeviceID'
url = 'https://'+hostname+'/ot-base/api/v1/devices/'+deviceID
data = {
'name':'enterLocationName',
'company':'enterCompanyName'
}
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.