Authentication
Authenticate with an API key โ the simplest and most reliable flow for servers, CI, and cron jobs. Mint an lh_โฆ key in the portal and pass it when you construct the client.
All snippets use these imports:
- Go SDK
- JS SDK
- CLI
import (
sdkclient "github.com/Backup-Data-io/go-sdk/client"
sdktypes "github.com/Backup-Data-io/go-sdk/types"
)
import { BackupClient } from "@backupdata/js-sdk";
npm install -g @backupdata/js-sdk
baas --help
The baas CLI is stateless (v0.1.5) โ it does not store a profile and has no auth login / auth whoami. Pass the portal key per invocation:
export BACKUPDATA_API_KEY="lh_..." # from Portal โ API Keys
export BACKUPDATA_WORKSPACE_ID="<id>" # from Portal โ Workspaces
baas snapshots --limit 5
baas backup ./db-dumps --api-key lh_... --workspace <id>
--private-key 0x... / BACKUPDATA_PRIVATE_KEY is accepted as an alternative to --api-key.
For servers, CI, and cron jobs, mint an API key in the portal and use the API key flow below. It is the most reliable path.
API key (recommended for automation)โ
This is the simplest and most common flow for backup jobs. When you pass an API key, the client is already authenticated โ you do not call Authenticate().
- Go SDK
- JS SDK
- CLI
import (
"log"
"os"
sdkclient "github.com/Backup-Data-io/go-sdk/client"
)
func newClient() *sdkclient.BackupClient {
c, err := sdkclient.NewBackupClient(sdkclient.BackupClientOptions{
APIURL: "https://api.backupdata.io", // API host
APIKey: os.Getenv("BACKUPDATA_API_KEY"), // lh_โฆ from the portal
WorkspaceID: os.Getenv("BACKUPDATA_WORKSPACE_ID"), // workspace UUID
})
if err != nil {
log.Fatalf("client init: %v", err)
}
return c
}
import { BackupClient } from "@backupdata/js-sdk";
function newClient() {
return new BackupClient({
apiKey: process.env.BACKUPDATA_API_KEY, // lh_โฆ from the portal
workspaceId: process.env.BACKUPDATA_WORKSPACE_ID, // workspace UUID
});
}
# Every invocation authenticates explicitly (no stored profile).
export BACKUPDATA_API_KEY="lh_xxxxxxxxxxxxxxxxxxxxxxxx"
export BACKUPDATA_WORKSPACE_ID="550e8400-e29b-41d4-a716-446655440000"
baas snapshots --limit 5
baas backup ./db-dumps --workspace $BACKUPDATA_WORKSPACE_ID --api-key $BACKUPDATA_API_KEY
# or inline: baas snapshots --api-key lh_... --workspace <id> --limit 5
Switching workspaces: call
client.setWorkspaceId(id)(Go:c.SetWorkspaceID(id)) to change the default, or passworkspaceIdinside the backup / restore options to override for a single call.
See API Keys for how to create, scope, and rotate keys.