> ## Documentation Index
> Fetch the complete documentation index at: https://www.1password.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 1Password Events API generic scripts

> [!WARNING]
>
> The legacy Events API v1 and v2 endpoints will stop working on June 30, 2027. [Migrate your existing integration to v3](https://www.1password.dev/events-api/v3/migrate-from-v2.md) before that date. For new integrations, [get started with Events API v3](https://www.1password.dev/events-api/v3/get-started.md).

These scripts use the legacy Events API with an Events Reporting bearer token.

To help you get started with the 1Password Events API we've put together a [repository of example scripts](https://github.com/1Password/events-api-generic) across several languages, including [JavaScript](https://github.com/1Password/events-api-generic/blob/main/eventsapi.js), [Python](https://github.com/1Password/events-api-generic/blob/main/eventsapi.py), [Ruby](https://github.com/1Password/events-api-generic/blob/main/eventsapi.rb), [Go](https://github.com/1Password/events-api-generic/blob/main/eventsapi.go), and [PHP.](https://github.com/1Password/events-api-generic/blob/main/eventsapi.php) The scripts will print up to 20 sign-in attempts and item usage events from the last 24 hours.

## Requirements

Before implementing any of the examples, or your own scripts, you'll need to generate a bearer token and store it in your 1Password account.

To get a bearer token, you can:

* [Set up a new Events Reporting integration.](https://www.1password.dev/events-api/v2/get-started.md#step-1-set-up-an-events-reporting-integration)
* [Issue a new token](https://www.1password.dev/events-api/v2/authorization.md#issue-a-bearer-token) in an existing integration.
* [Generate a token with 1Password CLI.](https://www.1password.dev/cli/reference/management-commands/events-api.md#events-api-create)

## Usage

All scripts use the `EVENTS_API_TOKEN` environment variable to load your API token.

We recommend setting `EVENTS_API_TOKEN` to a [secret reference](https://www.1password.dev/cli/secret-reference-syntax.md) that points to where your bearer token is saved in 1Password, to avoid revealing the token in plaintext. Then you can use [`op run`](https://www.1password.dev/cli/reference/commands/run/) with [1Password CLI](https://www.1password.dev/cli.md) to securely provision the token at runtime.

[Learn more about securely loading secrets from the environment.](https://www.1password.dev/cli/secrets-environment-variables.md)

For example, to set the `EVENTS_API_TOKEN` environment variable with an environment file, then use [`op run`](https://www.1password.dev/cli/reference/commands/run/) to run the PHP `eventsapi.php` script with the variable provisioned:

```shell events.env theme={null}
EVENTS_API_TOKEN="op://Vault/Item/token"
```

```
op run --env-file="./events.env" -- php eventsapi.php
```

To export the `EVENTS_API_TOKEN` environment variable, then use [`op run`](https://www.1password.dev/cli/reference/commands/run/) to run the Go `eventsapi.go` script with the variable provisioned:

> [tab] bash, sh, zsh, fish
>
> ```shell theme={null}
> EVENTS_API_TOKEN="op://Vault/Item/token" op run -- go run eventsapi.go
> ```

> [tab] Powershell
>
> 1. Export the necessary environment variables:
>
>    ```powershell theme={null}
>    $Env:EVENTS_API_TOKEN = "op://Vault/Item/token"
>    ```
>
> 2. Run op run -- with your command for starting the app:
>
>    ```powershell theme={null}
>    op run -- go run eventsapi.go
>    ```

## Learn more

* [Get started with the 1Password Events API](https://www.1password.dev/events-api/v2/get-started.md)
* [Issue or revoke bearer tokens for the Events API](https://www.1password.dev/events-api/v2/authorization.md#manage-bearer-tokens)
* [About 1Password Events Reporting security](https://support.1password.com/events-reporting-security/)
* [Workflow: Get data and analytics for your account](https://www.1password.dev/get-started/get-data-and-analytics.md)


## Related topics

- [Set up a legacy Events API integration](https://www.1password.dev/events-api/v2/get-started.md)
- [1Password Events API](https://www.1password.dev/events-api/v3.md)
- [1Password Events API changelog](https://www.1password.dev/events-api/v2/changelog.md)
