Skip to main content

Create & Update Historical Data

This endpoint allows you to create or update historical data programmatically.

We use a database technique called "upsert" which works as following: If there is already a entry with the same (company_id, meter_number, date) combination, the remaining fields (measured, temperature, etc.) will be updated. If there is no entry with the same combination, a new entry will be created.

Endpoint

POST: https://api.smart-mfg.net/historical-data

Body Parameters

ParameterRequiredTypeDescription
dataYesarrayAn array containing historical data entries. You must include at least 1 entry and no more than 1,000 entries.
data.*.dateYesdateThe date for the data entry. Must be in the format Y-m-d.
data.*.meter_numberYesstringThe meter number for the data entry. Must be a string with a maximum length of 255 characters.
data.*.day_of_weekNointegerThe day of the week for the data entry (0 for Sunday, 6 for Saturday). Must be between 0 and 6.
data.*.day_of_yearNointegerThe day of the year for the data entry. Must be between 1 and 366.
data.*.month_of_yearNointegerThe month of the year for the data entry. Must be between 1 and 12.
data.*.nominationNonumericThe nomination value for the data entry. Decimal places allowed.
data.*.measuredNonumericThe measured value for the data entry. Decimal places allowed.
data.*.temperature_maxNonumericThe maximum temperature for the data entry. Decimal places allowed.
data.*.temperature_meanNonumericThe mean temperature for the data entry. Decimal places allowed.
data.*.temperature_minNonumericThe minimum temperature for the data entry. Decimal places allowed.
data.*.precipitation_sumNonumericThe total precipitation for the data entry. Decimal places allowed.
data.*.humidity_maxNonumericThe maximum humidity for the data entry. Decimal places allowed.
data.*.humidity_meanNonumericThe mean humidity for the data entry. Decimal places allowed.
data.*.humidity_minNonumericThe minimum humidity for the data entry. Decimal places allowed.
data.*.wind_speed_maxNonumericThe maximum wind speed for the data entry. Decimal places allowed.
data.*.wind_speed_meanNonumericThe mean wind speed for the data entry. Decimal places allowed.
data.*.wind_speed_minNonumericThe minimum wind speed for the data entry. Decimal places allowed.
data.*.stationNostringThe station identifier for the data entry. Must be a string with a maximum length of 255 characters.
company_idNo **integer** Recommended (only if the user has multiple companies) to explicitly set what company you're sending data for.
testNobooleanIf set to true, it will validate your response, but not save any data.

Example Request

import requests

token = "YOUR_GENERATED_TOKEN"

headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/json",
"Content-Type": "application/json"
}

data = {
"data": [
{
"meter_number": "123",
"date": "2023-05-17",
"temperature_max": 75.5,
"temperature_mean": 70.0,
"temperature_min": 65.2,
"humidity_max": 80,
"humidity_mean": 75,
"humidity_min": 70,
"wind_speed_max": 10.5,
"wind_speed_mean": 8.2,
"wind_speed_min": 5.1,
"precipitation_sum": 0.2,
"station": "Station_1"
},
{
"meter_number": "456",
"date": "2023-05-18", # You can exclude any optional fields
},
{
"meter_number": "789",
"date": "2023-05-19",
"temperature_max": 80.5,
"temperature_mean": 75.0,
"temperature_min": 70.2,
"humidity_max": 85,
"humidity_mean": 80,
"humidity_min": 75,
"wind_speed_max": 15.5,
"wind_speed_mean": 12.2,
"wind_speed_min": 10.1,
"precipitation_sum": 0.5,
"station": "Station_2"
}
],
"company_id": 1, # Optional, recommended if the user has multiple companies
"test": True # Optional, exclude this line if you want to save the data
}

response = requests.post("https://api.smart-mfg.net/historical-data", headers=headers, json=data)
print(response.json())

if 200 <= response.status_code < 300:
print("Request successful!")
else:
print("Failed to create or update historical data.")

The API will return a JSON response with either a success message (Code 2xx), or a list of errors (Code 4xx).

Example Response (Success)

When test is True:

{
"message" : "Historical data validation rules passed."
}

When test is False:

{
"message" : "Data stored successfully."
}

Example Response (Error)

{
"errors": {
"company_id": [
"The provided company_id is invalid."
]
}
}