Skip to main content
You can use 1Password SDKs to securely load secrets into your code with secret references. Before you begin, follow the steps to get started with a 1Password SDK. You can retrieve secrets from supported field types. You can also retrieve one-time passwords using the otp attribute parameter. A valid secret reference should use the syntax:
op://<vault>/<item>/[section/]<field>
To get a one-time password, append the ?attribute=otp query parameter to a secret reference that points to a one-time password field in 1Password:
op://<vault>/<item>/[section/]one-time password?attribute=otp
See the examples folder in the 1Password Go, JavaScript, or Python SDK GitHub repository for example code you can quickly clone and test in your project.

Load a secret from 1Password

Replace the placeholder secret reference in the example with a secret reference URI that specifies the vault, item, section (if applicable), and field where the secret is saved in your 1Password account. If you have multiple vaults, items, or fields that share the same name, use a unique identifier instead of the name in the secret reference.
// Retrieves a secret from 1Password.
// Takes a secret reference as input and returns the secret to which it points.
secret, err := client.Secrets().Resolve(context.Background(), fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID))
if err != nil {
	panic(err)
}
fmt.Println(secret)
The resolve function resolves the secret reference and returns the value of the 1Password field it references. You can then use this value in your code, like to authenticate to another service.

Retrieve multiple secrets

You can use the secrets.resolveAll function to retrieve secrets from 1Password in bulk, improving the performance of the operation. Replace the placeholder secret references in the example with secret reference URIs that specify the vault, item, section (if applicable), and field where the secrets are saved in your 1Password account.
// Retrieves multiple secrets from 1Password.
// Takes multiple secret references as input and returns the secret to which it points.
secret, _ := client.Secrets().ResolveAll(
	context.Background(),
	[]string{
		fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID),
		fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID2),
	},
)
for _, s := range secret.IndividualResponses {
	if s.Error != nil {
		panic(string(s.Error.Type))
	}
	fmt.Println(s.Content.Secret)
}

Validate a secret reference

You can use the secret reference validation function to make sure that your secret reference is formatted correctly.
// Validate your secret reference
err := onepassword.Secrets.ValidateSecretReference(context.Background(), fmt.Sprintf("op://%s/%s/%s", vaultID, itemID, fieldID))
if err != nil {
	panic(err)
}
If the secret reference is formatted incorrectly, the SDK will return an error that describes the syntax problem. Learn more about secret references.

Learn more