# Event

Every time a log is created, a corresponding event will be generated and sent to you by **webhook**, if the appropriate subscription was set. Therefore, the event represents an occurrence in your workspace.

**NOTE:** All the events have a log property containing an entity log. The nature of the log, however, may change according to the subscription that triggered the event. For example, if the subscription is credit-note, the log in the event will be a CreditNoteLog.

### The Event object

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `id` | STRING | Unique id for the event. |
| `created` | STRING | Creation datetime. Example: "2022-01-01T00:00:00.000000+00:00". |
| `isDelivered` | STRING | Whether the event has been successfully delivered. Options: "true", "false". |
| `subscription` | STRING | Subscription that triggered the event. |
| `workspaceId` | STRING | ID of the workspace the event belongs to. |

### List Events

`GET /v2/event`

Get a list of non-deleted events in chunks of at most 100. If you need smaller chunks, use the limit parameter.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `after` | OPTIONAL | Date filter for Events created only after a specific date. Example: "2022-01-20" |
| `before` | OPTIONAL | Date filter for Events created only before a specific date. Example: "2022-02-20" |
| `cursor` | OPTIONAL | String used to get the next batch of results. Our SDKs handle this for you. |
| `isDelivered` | OPTIONAL | If false, only gets Events that haven't been delivered. If true, only gets Events that have already been delivered. |
| `limit` | OPTIONAL | Maximum number of Events to be retrieved. Max = 100. |
| `fields` | OPTIONAL | List of strings to filter response JSON keys. Not available in the SDKs. |

**Request**

```python
import starkinfra

events = starkinfra.event.query(limit=10, is_delivered=False)

for event in events:
    print(event)
```

**Response**

```python
Event(
    id=5719405850615809,
    log=CreditNote.Log(id=5155165527080961, type=created),
    created=2022-06-01T00:00:00.000000+00:00,
    is_delivered=False,
    subscription=credit-note,
    workspace_id=4019167990849536
)
```

### Get an Event

`GET /v2/event/:id`

Get a single Event by its id.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Unique id of the event entity. |
| `fields` | OPTIONAL | List of strings to filter response JSON keys. Not available in the SDKs. |

**Request**

```python
import starkinfra

event = starkinfra.event.get("5719405850615809")

print(event)
```

**Response**

```python
Event(
    id=5719405850615809,
    log=CreditNote.Log(id=5155165527080961, type=created),
    created=2022-06-01T00:00:00.000000+00:00,
    is_delivered=False,
    subscription=credit-note,
    workspace_id=4019167990849536
)
```

### Delete an Event

`DELETE /v2/event/:id`

Delete a single Event from the event list.

**Note:** This action cannot be undone.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the Event entity to be deleted. |

**Request**

```python
import starkinfra

event = starkinfra.event.delete("5719405850615809")

print(event)
```

**Response**

```python
Event(
    id=5719405850615809,
    log=CreditNote.Log(id=5155165527080961, type=created),
    created=2022-06-01T00:00:00.000000+00:00,
    is_delivered=False,
    subscription=credit-note,
    workspace_id=4019167990849536
)
```

### Update an Event

`PATCH /v2/event/:id`

The only information you can update in an Event is the isDelivered property. This can be useful when, after experiencing server downtime on your side, you list all events with isDelivered=false, process them, and then set them as delivered to stabilize your operations.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `id` | REQUIRED | Id of the event entity. Example: "5719405850615809" |
| `isDelivered` | REQUIRED | Bool signaling if the Event has or hasn't been successfully delivered. |

**Request**

```python
import starkinfra

event = starkinfra.event.update(
    "5719405850615809",
    is_delivered=True
)

print(event)
```

**Response**

```python
Event(
    id=5719405850615809,
    log=CreditNote.Log(id=5155165527080961, type=created),
    created=2022-06-01T00:00:00.000000+00:00,
    is_delivered=True,
    subscription=credit-note,
    workspace_id=4019167990849536
)
```

## Available Languages

Code samples on this page are in Python. The same content is available with samples in:

- [Python](https://docs.starkinfra.com/api/v2/event-python.md)
- [Node.js](https://docs.starkinfra.com/api/v2/event-node.md)
- [PHP](https://docs.starkinfra.com/api/v2/event-php.md)
- [Java](https://docs.starkinfra.com/api/v2/event-java.md)
- [Ruby](https://docs.starkinfra.com/api/v2/event-ruby.md)
- [Elixir](https://docs.starkinfra.com/api/v2/event-elixir.md)
- [.NET](https://docs.starkinfra.com/api/v2/event-dotnet.md)
- [Go](https://docs.starkinfra.com/api/v2/event-go.md)
- [Clojure](https://docs.starkinfra.com/api/v2/event-clojure.md)
- [cURL](https://docs.starkinfra.com/api/v2/event-curl.md)
