Global WatchGlobal Watch Docs
API Reference

Authentication

API Authentication

Global Watch API supports multiple authentication methods to suit different use cases. This guide covers how to authenticate your API requests securely.

Authentication Methods

MethodUse CaseSecurity Level
API KeysServer-to-server integrationsHigh
OAuth 2.0User-authorized applicationsHigh
Service TokensAutomated workflowsHigh

API Keys

API keys are the simplest way to authenticate with the Global Watch API. They're ideal for server-side applications and scripts.

Generating an API Key

  1. Log in to your Global Watch account
  2. Navigate to SettingsAPI Keys
  3. Click Generate New Key
  4. Provide a descriptive name for the key
  5. Select the appropriate permissions
  6. Click Create Key

Your API key will only be shown once. Copy it immediately and store it securely.

Using API Keys

Include your API key in the Authorization header:

curl -X GET "https://api.global.watch/v1/projects" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

API Key Permissions

When creating an API key, you can scope its permissions:

PermissionDescription
projects:readRead project data
projects:writeCreate and update projects
assets:readRead asset data
assets:writeCreate and update assets
members:readRead team member data
members:writeManage team members
billing:readRead billing information
adminFull administrative access

API Key Best Practices

Follow these best practices to keep your API keys secure.

  1. Never expose keys in client-side code - API keys should only be used server-side
  2. Use environment variables - Store keys in environment variables, not in code
  3. Rotate keys regularly - Generate new keys periodically and revoke old ones
  4. Use minimal permissions - Only grant the permissions your application needs
  5. Monitor usage - Review API key activity in your dashboard
// ✅ Good - Using environment variables
const apiKey = process.env.GLOBALWATCH_API_KEY;

// ❌ Bad - Hardcoded key
const apiKey = 'fw_live_abc123...';

Revoking API Keys

To revoke an API key:

  1. Go to SettingsAPI Keys
  2. Find the key you want to revoke
  3. Click the Revoke button
  4. Confirm the action

Revoking a key is immediate and irreversible. Any applications using the key will stop working.

OAuth 2.0

OAuth 2.0 is recommended for applications that act on behalf of users. It provides secure, scoped access without exposing user credentials.

OAuth Flow Overview

┌──────────┐                              ┌──────────────┐
│   User   │                              │  Global Watch │
└────┬─────┘                              └──────┬───────┘
     │                                           │
     │  1. User clicks "Connect Global Watch"     │
     │ ─────────────────────────────────────────>│
     │                                           │
     │  2. Redirect to authorization page        │
     │ <─────────────────────────────────────────│
     │                                           │
     │  3. User grants permission                │
     │ ─────────────────────────────────────────>│
     │                                           │
     │  4. Redirect with authorization code      │
     │ <─────────────────────────────────────────│
     │                                           │
     │  5. Exchange code for access token        │
     │ ─────────────────────────────────────────>│
     │                                           │
     │  6. Return access token                   │
     │ <─────────────────────────────────────────│

Setting Up OAuth

1. Register Your Application

  1. Go to SettingsDeveloperOAuth Applications
  2. Click Create Application
  3. Fill in the application details:
    • Name: Your application name
    • Redirect URIs: Authorized callback URLs
    • Scopes: Required permissions
  4. Save your Client ID and Client Secret

2. Authorization Request

Redirect users to the authorization endpoint:

https://global.watch/oauth/authorize?
  client_id=YOUR_CLIENT_ID&
  redirect_uri=https://yourapp.com/callback&
  response_type=code&
  scope=projects:read assets:read&
  state=random_state_string
ParameterDescriptionRequired
client_idYour OAuth application client IDYes
redirect_uriURL to redirect after authorizationYes
response_typeMust be codeYes
scopeSpace-separated list of permissionsYes
stateRandom string for CSRF protectionRecommended

3. Handle the Callback

After the user authorizes, they're redirected to your callback URL:

https://yourapp.com/callback?code=AUTH_CODE&state=random_state_string

4. Exchange Code for Token

Exchange the authorization code for an access token:

curl -X POST "https://api.global.watch/oauth/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET" \
  -d "code=AUTH_CODE" \
  -d "redirect_uri=https://yourapp.com/callback"

Response:

{
  "access_token": "fw_oauth_abc123...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "fw_refresh_xyz789...",
  "scope": "projects:read assets:read"
}

5. Use the Access Token

Include the access token in API requests:

curl -X GET "https://api.global.watch/v1/projects" \
  -H "Authorization: Bearer fw_oauth_abc123..."

Refreshing Tokens

Access tokens expire after 1 hour. Use the refresh token to get a new access token:

curl -X POST "https://api.global.watch/oauth/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=refresh_token" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET" \
  -d "refresh_token=fw_refresh_xyz789..."

OAuth Scopes

ScopeDescription
profileRead user profile information
projects:readRead project data
projects:writeCreate and modify projects
assets:readRead asset data
assets:writeCreate and modify assets
members:readRead team member information
offline_accessRequest refresh tokens

Service Tokens

Service tokens are designed for automated workflows and CI/CD pipelines. They provide non-expiring access with specific permissions.

Creating a Service Token

  1. Go to SettingsAPI KeysService Tokens
  2. Click Create Service Token
  3. Configure:
    • Name: Descriptive name for the token
    • Permissions: Select required permissions
    • IP Allowlist: (Optional) Restrict to specific IPs
  4. Click Create

Using Service Tokens

Service tokens work the same as API keys:

curl -X GET "https://api.global.watch/v1/projects" \
  -H "Authorization: Bearer fw_service_abc123..."

IP Allowlisting

For enhanced security, restrict service tokens to specific IP addresses:

{
  "name": "CI/CD Pipeline Token",
  "permissions": ["projects:read", "assets:write"],
  "ip_allowlist": [
    "192.168.1.0/24",
    "10.0.0.1"
  ]
}

Security Best Practices

Token Storage

EnvironmentRecommended Storage
ServerEnvironment variables, secrets manager
CI/CDPipeline secrets (GitHub Actions, GitLab CI)
Local Development.env.local file (gitignored)

Example: Secure Token Usage

// server-side only
import { GlobalWatch } from '@globalwatch/sdk';

// Load from environment
const client = new GlobalWatch({
  apiKey: process.env.GLOBALWATCH_API_KEY,
});

// Never log tokens
console.log('Connecting to Global Watch...'); // ✅
console.log(`Using key: ${apiKey}`); // ❌ Never do this

Handling Token Errors

Error CodeDescriptionAction
401Invalid or expired tokenCheck token validity, refresh if OAuth
403Insufficient permissionsRequest additional scopes
429Rate limit exceededImplement backoff, check limits
try {
  const projects = await client.projects.list();
} catch (error) {
  if (error.status === 401) {
    // Token expired - refresh or re-authenticate
    await refreshToken();
  } else if (error.status === 403) {
    // Insufficient permissions
    console.error('Missing required permissions');
  }
}

Testing Authentication

Verify Your Token

Test your authentication setup:

curl -X GET "https://api.global.watch/v1/auth/verify" \
  -H "Authorization: Bearer YOUR_TOKEN"

Success response:

{
  "valid": true,
  "type": "api_key",
  "permissions": ["projects:read", "projects:write", "assets:read"],
  "account_id": "acc_abc123",
  "expires_at": null
}

Common Issues

"Invalid token" error

  • Verify the token is copied correctly (no extra spaces)
  • Check if the token has been revoked
  • Ensure you're using the correct environment (production vs. development)

"Insufficient permissions" error

  • Review the token's granted permissions
  • Request additional scopes if using OAuth
  • Generate a new API key with required permissions

On this page