Skip to main content

1Password Events API generic scripts

info

To help you get started with the Events API we've put together a repository of example scripts across several languages, including JavaScript, Python, Ruby, Go, and PHP. The scripts will print at most 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 issue a bearer token:

  1. Sign in to your account on 1Password.com and select Developer in the sidebar.
  2. Choose the Events Reporting integration where you want to issue a token and select Add a token.
  3. Enter a name for the bearer token and choose when it will expire. Select or deselect the event types the token has access to, then select Issue Token.
  4. Select Save in 1Password and choose which vault to save your token to. Then select View Integration Details.
You can also generate an API bearer token through the command-line tool.

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 that points to where your bearer token is saved in 1Password, to avoid revealing the token in plaintext. Then you can use op run with 1Password CLI to securely provision the token at runtime.

Learn more about securely loading secrets from the environment.

For example, to set the EVENTS_API_TOKEN environment variable with an environment file, then use op run to run the PHP eventsapi.php script with the variable provisioned:

events.env

To export the EVENTS_API_TOKEN environment variable, then use op run to run the Go eventsapi.go script with the variable provisioned:

Learn more

Was this page helpful?