> ## 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

<Note>
  If you're new to Events Reporting, [learn how to get started with 1Password Events API](/events-api/get-started/).
</Note>

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.](/events-api/get-started#step-1-set-up-an-events-reporting-integration)
* [Issue a new token](/events-api/authorization#issue-a-bearer-token) in an existing integration.
* [Generate a token with 1Password CLI.](/cli/reference/management-commands/events-api/#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](/cli/secret-reference-syntax/) that points to where your bearer token is saved in 1Password, to avoid revealing the token in plaintext. Then you can use [`op run`](/cli/reference/commands/run/) with [1Password CLI](/cli/) to securely provision the token at runtime.

[Learn more about securely loading secrets from the environment.](/cli/secrets-environment-variables/)

For example, to set the `EVENTS_API_TOKEN` environment variable with an environment file, then use [`op run`](/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`](/cli/reference/commands/run/) to run the Go `eventsapi.go` script with the variable provisioned:

<Tabs groupId="shell">
  <Tab title="bash, sh, zsh, fish">
    ```shell theme={null}
    EVENTS_API_TOKEN="op://Vault/Item/token" op run -- go run eventsapi.go
    ```
  </Tab>

  <Tab title="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
       ```
  </Tab>
</Tabs>

## Learn more

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