1Password Events API generic scripts
If you're new to Events Reporting, learn how to get started with 1Password Events Reporting.
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:
- Sign in to your account on 1Password.com and select Developer in the sidebar.
- Choose the Events Reporting integration where you want to issue a token and select Add a token.
- 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.
- Select Save in 1Password and choose which vault to save your token to. Then select View Integration Details.
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:
- bash, sh, zsh, fish
- Powershell
-
Export the necessary environment variables:
-
Run op run -- with your command for starting the app: