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
| Parameter | Required | Type | Description |
|---|---|---|---|
| data | Yes | array | An array containing historical data entries. You must include at least 1 entry and no more than 1,000 entries. |
| data.*.date | Yes | date | The date for the data entry. Must be in the format Y-m-d. |
| data.*.meter_number | Yes | string | The meter number for the data entry. Must be a string with a maximum length of 255 characters. |
| data.*.day_of_week | No | integer | The day of the week for the data entry (0 for Sunday, 6 for Saturday). Must be between 0 and 6. |
| data.*.day_of_year | No | integer | The day of the year for the data entry. Must be between 1 and 366. |
| data.*.month_of_year | No | integer | The month of the year for the data entry. Must be between 1 and 12. |
| data.*.nomination | No | numeric | The nomination value for the data entry. Decimal places allowed. |
| data.*.measured | No | numeric | The measured value for the data entry. Decimal places allowed. |
| data.*.temperature_max | No | numeric | The maximum temperature for the data entry. Decimal places allowed. |
| data.*.temperature_mean | No | numeric | The mean temperature for the data entry. Decimal places allowed. |
| data.*.temperature_min | No | numeric | The minimum temperature for the data entry. Decimal places allowed. |
| data.*.precipitation_sum | No | numeric | The total precipitation for the data entry. Decimal places allowed. |
| data.*.humidity_max | No | numeric | The maximum humidity for the data entry. Decimal places allowed. |
| data.*.humidity_mean | No | numeric | The mean humidity for the data entry. Decimal places allowed. |
| data.*.humidity_min | No | numeric | The minimum humidity for the data entry. Decimal places allowed. |
| data.*.wind_speed_max | No | numeric | The maximum wind speed for the data entry. Decimal places allowed. |
| data.*.wind_speed_mean | No | numeric | The mean wind speed for the data entry. Decimal places allowed. |
| data.*.wind_speed_min | No | numeric | The minimum wind speed for the data entry. Decimal places allowed. |
| data.*.station | No | string | The station identifier for the data entry. Must be a string with a maximum length of 255 characters. |
| company_id | No ** | integer | ** Recommended (only if the user has multiple companies) to explicitly set what company you're sending data for. |
| test | No | boolean | If 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."
]
}
}