Using Access Tokens - API Authentication Examples

API Authentication

Access tokens are used in API requests via the Authorization header:

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     https://api.example.com/v1/endpoint

Token Format

  • Tokens are long alphanumeric strings
  • Include the full token in the Authorization header
  • Use the format: Bearer <token>

Common Use Cases

CI/CD Pipelines

Authenticate automated test runs:

# Example: Running tests in CI/CD
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
     -X POST \
     https://api.example.com/v1/test-runs

Integration Services

Connect third-party tools (Zapier, Jenkins, etc.):

# Example: Zapier webhook
curl -H "Authorization: Bearer YOUR_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"data": "..."}' \
     https://api.example.com/v1/webhook

Automation Scripts

Run scheduled tasks and reports:

# Example: Python script
import requests

headers = {
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://api.example.com/v1/test-cases",
    headers=headers
)

API Clients

Build custom integrations:

// Example: JavaScript/Node.js
const axios = require('axios');

const client = axios.create({
  baseURL: 'https://api.example.com/v1',
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
  }
});

client.get('/test-runs')
  .then(response => console.log(response.data));

Security Considerations

  1. Never Commit Tokens: Never commit tokens to version control
  2. Use Environment Variables: Store tokens in secure environment variables
  3. Rotate Regularly: Periodically create new tokens and revoke old ones
  4. Monitor Usage: Regularly review token usage and disable unused tokens
  5. Revoke Compromised Tokens: Immediately delete tokens if they’re exposed

Next Steps

Was this page helpful?