# Add Events

### Add Event Data of Devices

Make sure that event data, which shall be taken into consideration by MOOST Recommender Platform, are forwarded to MOOST via MOOST API.

See [event-types](https://doc.moost.io/technical-integration/cloud-to-cloud-integration/moost-api-integration/forward-events/event-types "mention") to get an overview which events should be forwarded for which devices in which periodicity.

### Event Data Structure <a href="#building-data-structure" id="building-data-structure"></a>

Following example depicts an event structure of a energy consumption event.

```json
{
  "id": "6703cfa2fa7bfc35eb1f74d0",
  "customerId": "656730be2bc9719e6e5ed51d",
  "customerBuildingId": "99900000C048ADA6",
  "deviceId": "c8f09e83046c",
  "deviceName": "Sinemaa main meter",
  "source": "GATEWAY",
  "type": "ENERGY_CONSUMPTION",
  "value": 858.71,
  "timestamp": 1727992800000
}
```

#### **Data Structure Attributes**

<table><thead><tr><th width="239">Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><code>id</code></td><td>The event ID on MOOST side (is generated when inserting a new event)</td></tr><tr><td><code>customerId</code></td><td>The ID of the customer (cannot be set or change)</td></tr><tr><td><code>customerBuildingId</code></td><td>The building ID on customer side</td></tr><tr><td><code>deviceId</code></td><td>The ID of the device which is producing this event (should refer to the device within the building, see <a data-mention href="../synchronize-buildings-and-devices#building-data-structure">#building-data-structure</a> </td></tr><tr><td><code>deviceName</code></td><td>The name of the device which is producing this event.<br>Remark: if devices have not an own name, the product name can be used.</td></tr><tr><td><code>source</code></td><td>The device which is related to this event. See <a data-mention href="synchronize-buildings-and-devices/device-types">device-types</a><br>Remark: device type <code>GATEWAY</code> is used, when this is a data point for the whole household / building.</td></tr><tr><td><code>type</code></td><td>The event type of this event. This value also implies the data unit. See <a data-mention href="forward-events/event-types">event-types</a></td></tr><tr><td><code>value</code></td><td>The value of the event datapoint.<br>Remark: must be a number</td></tr><tr><td><code>timestamp</code></td><td>Time of the event (Epoch Time in seconds (UTC))</td></tr></tbody></table>

### Add an Event

For sending new Events to the MOOST Recommender Platform the below endpoint can be used.

{% openapi src="<https://doc.api.moost.io/docs/openapi/openapi.json>" path="/events/v1" method="post" %}
<https://doc.api.moost.io/docs/openapi/openapi.json>
{% endopenapi %}

#### Example with CURL

```
# make sure ACCESS_TOKEN is set and valid (see "Request Access Token")
curl -X POST "https://api.moost.io/events/v1" \
     -H  "Authorization: Bearer $ACCESS_TOKEN" \
     -H  "Content-Type: application/json" \
     -d "{\"timestamp\":1657029000,\"customerId\":\"656730be2bc9719e6e5ed51d\",\"customerBuildingId\":\"999000009C54AAAA\",\"deviceId\":\"17306deb97e0f94609f13e22\",\"deviceName\":\"Device Link Car\",\"value\":99.9,\"type\":\"STATE_OF_CHARGE_RATE\",\"source\":\"CAR\"}"
```

### Add a batch of historical events

In case you want to add a batch of historical events, following endpoint can be used.&#x20;

Remark: historical events will not be processed by the rule engine during insertion.

## POST /events/historical/v1

> Inserts historical events to the database. I.e. these events are not processed by the rule engine when receiving these events.Event customerId has to be in-line with customerId of the JWT).

```json
{"openapi":"3.0.3","info":{"title":"MOOST Public API","version":"latest"},"servers":[{"url":"https://api.moost.io"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","name":"bearerAuth","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"Event":{"type":"object","properties":{"timestamp":{"type":"integer","format":"int64"},"customerId":{"type":"string","pattern":"^[a-zA-Z0-9]{24}$"},"customerBuildingId":{"type":"string","pattern":"^[a-zA-Z0-9:._-]{1,100}$"},"deviceId":{"type":"string","pattern":"^[a-zA-Z0-9:._-]{3,64}$"},"deviceName":{"type":"string","pattern":"^.{1,100}$"},"value":{"type":"number","format":"float"},"type":{"type":"string","enum":["CHARGING_MODE","DEVICE_STATUS","ENERGY_CONSUMPTION","ENERGY_CONSUMPTION_LAST_24H","ENERGY_CONSUMPTION_YESTERDAY","ENERGY_EXCESS_LAST_24H","ENERGY_EXCESS_YESTERDAY","ENERGY_GENERATION_LAST_24H","ENERGY_GENERATION_YESTERDAY","ENERGY_IMPORT","ENERGY_IMPORT_YESTERDAY","ENERGY_EXPORT","ENERGY_EXPORT_YESTERDAY","EXPECTED_OUTSIDE_TEMPERATURE","EXPECTED_OUTSIDE_TEMPERATURE_4DAYS","GRID_POWER_CONSUMPTION","GRID_POWER_CONSUMPTION_ANOMALY_SCORE","IS_LOW_TARIFF_HOURS","POWER_CONSUMPTION","POWER_CONSUMPTION_FORECAST_1H","POWER_CONSUMPTION_FORECAST_24H","POWER_EXCESS","POWER_GENERATION","POWER_GENERATION_FORECAST_1H","POWER_GENERATION_FORECAST_1H_MIN","POWER_GENERATION_FORECAST_24H","POWER_GENERATION_FORECAST_48H","POWER_GENERATION_FORECAST_DAY_AFTER_TOMORROW","POWER_GENERATION_FORECAST_TOMORROW","SELF_CONSUMPTION_RATE","SELF_CONSUMPTION_RATE_YESTERDAY","SELF_SUFFICIENCY_RATE","SELF_SUFFICIENCY_RATE_YESTERDAY","STATE_OF_CHARGE_FORECAST_RATE","STATE_OF_CHARGE_RATE","SWITCH_STATE","TEMPERATURE","WATER_TEMPERATURE","POWER_CONSUMPTION_BASE_LOAD","DYNAMIC_TARIFF_PRICE","DYNAMIC_TARIFF_PRICE_FORECAST_1H","DYNAMIC_TARIFF_LOWEST_PRICE_FORECAST_TOMORROW","IS_HIGH_TARIFF_HOURS","ENERGY_EXCESS","ENERGY_BASE_CONSUMPTION","ENERGY_CONSUMPTION_FORECAST_1H","ENERGY_CONSUMPTION_FORECAST_24H","ENERGY_GENERATION","ENERGY_GENERATION_FORECAST_1H","ENERGY_GENERATION_FORECAST_24H","GRID_ENERGY_CONSUMPTION","GRID_ENERGY_CONSUMPTION_YESTERDAY","GRID_ENERGY_CONSUMPTION_ANOMALY_SCORE","GRID_ENERGY_BASE_CONSUMPTION","ENERGY_GENERATION_FORECAST_DAY_AFTER_TOMORROW","ENERGY_GENERATION_FORECAST_TOMORROW","GLOBAL_HORIZONTAL_IRRADIATION_FORECAST_TOMORROW_HOURLY","GLOBAL_HORIZONTAL_IRRADIATION_FORECAST_TOMORROW","ENERGY_CONSUMPTION_FORECAST_TOMORROW","ENERGY_CONSUMPTION_FORECAST_DAY_AFTER_TOMORROW","GRID_BASE_LOAD_CONSUMPTION","DYNAMIC_TARIFF_PRICE_FORECAST_24H","GRID_POWER_CONSUMPTION_YESTERDAY"]},"source":{"type":"string","enum":["APPLIANCE","BATTERY","CAR","CAR_CHARGER","ENERGY_MEASUREMENT","GATEWAY","HEAT_PUMP","INPUT_DEVICE","INVERTER","MOOST","SMART_METER","SMART_PLUG","SWITCH","THERMOSTAT","THERMAL_ZONE","THERMAL_STORAGE","WATER_HEATER","WALL_TABLET","SOLAR_PANEL","DISHWASHER","DRYER","ENTERTAINMENT","LIGHTING","OVEN","REFRIGERATION","WASHING_MACHINE"]},"forecastTimestamp":{"type":"integer","format":"int64"},"ingestionTimestamp":{"type":"integer","format":"int64"}},"required":["customerBuildingId","customerId","deviceId","deviceName","type","value"]}}},"paths":{"/events/historical/v1":{"post":{"tags":["PublicAPI"],"summary":"Inserts historical events to the database. I.e. these events are not processed by the rule engine when receiving these events.Event customerId has to be in-line with customerId of the JWT).","operationId":"insertHistoricalEventsV1","requestBody":{"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Event"}}}},"required":true},"responses":{"200":{"description":"Success. All events have been inserted."},"400":{"description":"Invalid event data.","content":{"*/*":{"schema":{"type":"object","additionalProperties":{"type":"string"}}}}},"500":{"description":"Internal error. None or only part of the data could be written."}}}}}}
```
