How It Works
Generate a Token
Obtain a signed JWT token from the Zygo API while logged in via the browser or using an existing valid token.
Generating a Token
You must be logged in via the browser to generate your first token. After that, you can use the token itself to generate new tokens.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
expiration | integer (query) | 600 | Token lifetime in seconds |
Using the Token
Pass the token in thetoken header on every request. No session cookie is needed.
- curl
- Python
- JavaScript
Token vs. Session
Understanding the difference between the two authentication methods:| Browser Session | API Token | |
|---|---|---|
| How it works | Cookie-based, managed by Flask-Login | Stateless JWT in token header |
| Tenant context | Set once via the UI or /session/{tenant_id} | Determined per-request from the URL |
| State | Stateful — server stores session data | Stateless — no server-side state |
| Best for | Web UI interactions | Scripts, integrations, CI/CD |
| Login count | Incremented on login | Not incremented |
| Multi-tenant | Switch tenants with /session/{tenant_id} | Access any tenant per-request via URL |
Multi-Tenant Access
Unlike browser sessions where you switch tenants, API tokens let you access any tenant you’re a member of by changing thetenant_id in the URL:
Error Responses
| Status | Meaning |
|---|---|
401 | Token is missing, invalid, or expired |
403 | Token is valid but you lack permission (wrong role or not a tenant member) |
404 | Resource not found (or belongs to a tenant you don’t have access to) |
For security, Zygo returns
404 rather than 403 when you try to access a specific resource in a tenant you’re not a member of. This prevents leaking information about whether a resource exists.Security Best Practices
Use short expiration times
Use short expiration times
Set token expiration to the minimum duration you need. For scripts that run once, 600 seconds (10 minutes) is reasonable. For long-running integrations, consider refreshing the token periodically rather than using a very long expiration.
Never commit tokens to source control
Never commit tokens to source control
Store tokens in environment variables or a secrets manager. Treat them like passwords.
Use one token per integration
Use one token per integration
If you have multiple scripts or services calling the API, generate a separate token for each. This makes it easier to revoke access if one is compromised.
Rotate tokens regularly
Rotate tokens regularly
Tokens are short-lived by design. Build your integrations to handle token refresh gracefully.