# Events

Stelace Events let you know about any data update on your platform, enabling custom logic with Webhooks and Workflows.

Core Events are automatically created when the state of most API objects changes. You can also emit your own custom Events.

# Event object

Each Event is triggered on a specific object, of which name is standardized in camelCase like assetType related to any asset_type__* event.

Events can be used in many different ways, including:

  • Workflows, that are executed on our servers after being triggered by Events, enabling you to develop a serverless platform.
  • Webhooks can send Events to your own servers or external systems.

# Replay

Events have an infinite number of use cases, one of the most powerful being history browsing or Events replay for a given object on your platform, like an Asset:

await stelace.events.list({
  objectId: 'ast_lCfxJNs10rP1g2Mww0rP'
})

# Core Events

You can find a full list of Events in API reference API .

# Example

Here is a sample event object:

{
  "id": "evt_WWRfQps1I3a1gJYz2I3a",
  "createdDate": "2018-03-27T21:54:34.233Z",
  "type": "asset__created",
  "apiVersion": "2019-05-04",
  "objectType": "asset",
  "objectId": "ast_lCfxJNs10rP1g2Mww0rP",
  "object": { // full object itself
    "id": "ast_lCfxJNs10rP1g2Mww0rP",
    "name": "Ford Gran Torino",
    "description": "Muscle Car, 1972",
    "ownerId": "usr_WHlfQps1I3a1gJYz2I3a",
    "categoryId": "ctgy_ejQQps1I3a1gJYz2I3a",
    "validated": true,
    "active": true,
    "locations": [
      {
        "latitude": 34.099426,
        "longitude": -118.337097
      }
    ],
    "assetTypeId": "typ_MGsfQps1I3a1gJYz2I3a",
    "quantity": 1,
    "price": 10,
    "currency": "USD",
    "customAttributes": {},
    "metadata": {},
    "platformData": {},
    "createdDate": "2018-03-27T21:54:34.233Z",
    "updatedDate": "2018-04-06T16:04:39.331Z",
    "livemode": false
  },
  "changesRequested": null,
  "relatedObjectsIds": {
    "ownerId": "usr_WHlfQps1I3a1gJYz2I3a",
    "categoryId": "ctgy_ejQQps1I3a1gJYz2I3a",
    "assetTypeId": "typ_MGsfQps1I3a1gJYz2I3a"
  },
  "emitter": "core",
  "metadata": {}
}

# Update Events

For convenience, any core *__updated Event expose a changesRequested property including all changes submitted to the given object’s update endpoint, which originally triggered the Event.

Core Events also expose a relatedObjectsIds object pointing to objects that are automatically fetched in Workflows.

# Custom Events

You can create Custom Events with any type provided you don’t use Stelace naming convention with two underscores in a row as in asset__created.

await stelace.events.create({
  type: 'custom-event',
  objectId: 'ast_lCfxJNs10rP1g2Mww0rP',
  metadata: {
    attr: 'might be useful in Webhooks or Workflows',
    values: [{ anything: true }]
  }
})

objectId is very useful as it will ensure full object is available in emitted Event for your Webhooks or Workflows, as if it was a core Event.