Manage Measurements
Create measurements
This code creates a measurement by providing (my Swagger):
- Datatype: e.g. number, boolean, string ...
- Name: Tank1_Temperature
- Status: e.g. Active, Paused ...
Via POST https://historian.mycompany.com:18000/api/measurements/excel, an Excel file can be uploaded to bulk create/update measurements.
def create_measurement(database_uuid, collector_uuid, datatype, name, status):
payload = {
"DatabaseUUID": database_uuid,
"CollectorUUID": collector_uuid,
"Datatype": datatype,
"Name": name,
"Status": status
}
resp = session.post(f"{BASE_URL}/measurements", json=payload, timeout=30)
resp.raise_for_status()
return resp.json()
# fill in the database and collector UUID before executing
new_measurement = create_measurement("my-database-uuid", "my-collector-uuid", "number", "Tank1_Temperature", "Active")
print(json.dumps(new_measurement, indent=2))For Historian versions below v8.0.0, the PUT https://historian.mycompany.com:18000/api/measurements endpoint for bulk updates is PATCH https://historian.mycompany.com:18000/api/measurements instead. In v8.0.0 and higher, PATCH https://historian.mycompany.com:18000/api/measurements still exists, but expects a different data structure. This is a breaking change as listed in the changelogchangelog.
Update a measurement
This code updates a measurement by providing (my Swagger):
- Datatype: e.g. number, boolean, string, ...
- Name: Tank1_Temperature
- Status: e.g. Active, Paused ...
Use the PUT https://historian.mycompany.com:18000/api/measurements to create multiple measurements at once too.
def update_measurement(measurement_uuid: str, payload):
resp = session.put(f"{BASE_URL}/measurements/{measurement_uuid}", json=payload, timeout=30)
resp.raise_for_status()
return resp.json()
update_payload = {
"DatabaseUUID": "my-database-uuid",
"CollectorUUID": "my-collector-uuid",
"Datatype": "string",
"Name": "Tank1_Temperature",
"Status": "Paused"
}
updated_measurement = update_measurement("my-measurement-uuid", update_payload)
print(json.dumps(updated_measurement, indent=2))Delete a measurement
This code deletes a measurement given the measurement UUID (my Swagger).
DELETE https://historian.mycompany.com:18000/api/measurements/{measurement_uuid} (Replace {measurement_uuid} with your measurement UUID)
def delete_measurement(measurement_uuid: str):
resp = session.delete(f"{BASE_URL}/measurements/{measurement_uuid}", timeout=30)
resp.raise_for_status()
return resp.json()
delete_measurement("my-measurement-uuid")