SDKsGo SDKAdmin API
Service Accounts
Manage service accounts and API keys with the Go SDK.
Service Accounts
CreateServiceAccount()
sa, err := client.Admin.CreateServiceAccount(ctx, &avnologyid.CreateServiceAccountParams{
Name: "CI/CD Pipeline",
Description: "Deploys and syncs users",
OrganizationID: "org_abc123",
Scopes: []string{"users:read", "users:write"},
OwnerID: "usr_jane",
})
if err != nil {
log.Fatal(err)
}
fmt.Println("Service account:", sa.ID)CreateAPIKey()
key, err := client.Admin.CreateAPIKey(ctx, &avnologyid.CreateAPIKeyParams{
ServiceAccountID: "sa_abc123",
Name: "production-key",
ExpiresIn: 90 * 24 * 3600,
Scopes: []string{"users:read"},
})
if err != nil {
log.Fatal(err)
}
fmt.Println("API key (save now):", key.Key)
fmt.Println("Key prefix:", key.Prefix)RotateAPIKey()
newKey, err := client.Admin.RotateAPIKey(ctx, &avnologyid.RotateAPIKeyParams{
APIKeyID: "key_abc123",
GracePeriodHours: 48,
})
if err != nil {
log.Fatal(err)
}
fmt.Println("New key:", newKey.Key)ListServiceAccounts()
result, err := client.Admin.ListServiceAccounts(ctx, &avnologyid.ListServiceAccountsParams{
OrganizationID: "org_abc123",
})See also
- Client credentials -- M2M token flow
- Users -- User management