Skip to main content
Beta You can use 1Password SDKs to programmatically read environment variables stored in 1Password Environments (beta) and use them in your applications.

Requirements

To use this feature, you’ll need to install the beta version of the Go, JS, or Python SDK:
go get github.com/1password/onepassword-sdk-go@v0.4.1-beta.1

Read environment variables

To read environment variables stored in an Environment, use the GetVariables() method. Replace <your-environment-id> with the Environment’s ID.
res, err := client.Environments().GetVariables(context.Background(), "<your-environment-id>")
if err != nil {
	panic(err)
}
for _, env := range res.Variables {
	fmt.Printf("Variable %s: %s (hidden: %t)\n", env.Name, env.Value, env.Masked)
}
The method returns a GetVariablesResponse struct that contains a list of the environment variables stored in the Environment.
// Response containing the full set of environment variables from an Environment.
type GetVariablesResponse struct {
	// List of environment variables.
	Variables []EnvironmentVariable `json:"variables"`
}
Each EnvironmentVariable struct in the response contains the following:
  • Name: The environment variable’s name (for example, DB_HOST).
  • Value: The environment variable’s value.
  • Masked: A boolean that indicates whether the value is hidden by default in the 1Password app.
// Represents an environment variable (name:value pair) and its masked state
type EnvironmentVariable struct {
	// An environment variable's name
	Name string `json:"name"`
	// An environment variable's value
	Value string `json:"value"`
	// An environment variable's masked state
	Masked bool `json:"masked"`
}
1Password Environment variables are masked by default. To change this:
  1. Open and unlock the 1Password desktop app.
  2. Select Developer > View Environments.
  3. Choose the Environment, select Edit, then select the vertical ellipsis next to the variable and select Show value by default.

Appendix: Get an Environment’s ID

To read environment variables from a 1Password Environment, you’ll need its unique identifier (ID). You can find this ID in the 1Password desktop app:
  1. Open and unlock the 1Password desktop app.
  2. Navigate to Developer > View Environments.
  3. Select View environment next to the Environment you want to fetch.
  4. Select Manage environment > Copy environment ID.