Create & Update Forecasted Data
This endpoint allows you to create or update forecasted 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 nomination value 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/forecasted-data
Body Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| data | Yes | array | An array containing forecasted data entries. You must include at least 1 entry and no more than 15,000 entries in the array. |
| data.*.meter_number | Yes | string | The meter number for the data entry. Must be a string with a maximum length of 255 chars. |
| data.*.date | Yes | date | The date for the data entry. Must be in the format Y-m-d. |
| data.*.nomination | Yes | numeric | The nomination value for the data entry. |
| 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",
"nomination": 100.12345 # Decimal values for demonstration
},
{
"meter_number": "456",
"date": "2023-05-18",
"nomination": 200.75
}
],
"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/forecasted-data", headers=headers, json=data, timeout=300) # You may run into python timeout issues if you upload > 1000 data points, this is how you can increase it
print(response.json())
if 200 <= response.status_code < 300:
print("Request successful!")
else:
print("Failed to create or update forecasted 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" : "Forecasted data validation rules passed."
}
When test is False:
{
"message" : "Data stored successfully."
}
Example Response (Error)
{
"errors": {
"meter_numbers": [
"The meter numbers field is required."
]
}
}