Upsert events

async AsyncCogniteClient.events.upsert(
item: Event | EventWrite | Sequence[Event | EventWrite],
mode: Literal['patch', 'replace'] = 'patch',
) → Event | EventList

Upsert events, i.e., update if it exists, and create if it does not exist.

Deprecated since version 8.23.0: The Events API is deprecated and is scheduled for removal on 2027-12-31. Move events to records, CogniteActivity or CogniteMaintenanceOrder in the core data model. See https://docs.cognite.com/cdf/deprecated for details and migration guidance.

Note this is a convenience method that handles the upserting for you by first calling update on all items, and if any of them fail because they do not exist, it will create them instead.

For more details, see Upsert.

Parameters:
  • item (Event | EventWrite | Sequence[Event | EventWrite]) – Event or list of events to upsert.

  • mode (Literal['patch', 'replace']) – Whether to patch or replace in the case the events are existing. If you set ‘patch’, the call will only update fields with non-null values (default). Setting ‘replace’ will unset any fields that are not specified.

Returns:

The upserted event(s).

Return type:

Event | EventList

Examples

Upsert for events:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import EventWrite
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> existing_event = client.events.retrieve(id=1)
>>> existing_event.description = "New description"
>>> new_event = EventWrite(external_id="new_event", description="New event")
>>> res = client.events.upsert([existing_event, new_event], mode="replace")