API Authentication

Authentication Methods

The BreakBlocks API supports two authentication methods: session-based authentication for web applications and API key authentication for server-to-server communication.

Session-Based Authentication

When you log into BreakBlocks.com, your browser automatically receives a session cookie. This cookie is used to authenticate your requests.

// JavaScript with Fetch API
fetch('https://api.breakblocks.com/api/v0.1/servers/find?limit=10', {
  method: 'GET',
  credentials: 'include' // Include session cookies
})
.then(response => response.json())
.then(data => console.log(data));

API Key Authentication

API keys are for server-to-server authentication. Create and manage your keys from your user dashboard.

// Using cURL with API Key
curl -X GET "https://api.breakblocks.com/api/v0.1/servers/find?limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Creating API Keys

To create an API key:

  1. Log in to your BreakBlocks account
  2. Navigate to your user profile/settings
  3. Find the "API Keys" section
  4. Click "Generate New Key"
  5. Copy your key (you won't be able to see it again)

Protected vs Public Endpoints

Endpoint Type Authentication Required Examples
Public No /servers/find, /status/ping, /metadata/*
Protected Yes /user/apikeys

Error Responses

401 Unauthorized: Missing or invalid authentication credentials

{
  "success": false,
  "message": "Unauthorized: Invalid API key or session"
}

403 Forbidden: Authenticated but lacking required permissions

{
  "success": false,
  "message": "Forbidden: You don't have permission to access this resource"
}

Best Practices

  • Keep API Keys Secret: Never commit API keys to version control or expose them in client-side code
  • Use HTTPS: Always use HTTPS when making authenticated requests
  • Rotate Keys: Periodically regenerate API keys for security
  • Use Environment Variables: Store API keys in environment variables or secrets management systems
  • Set Expiration: Consider setting expiration dates on API keys for added security

Example: Authenticated Request with Axios

// JavaScript with Axios
const axios = require('axios');

const apiKey = process.env.BREAKBLOCKS_API_KEY;
const response = await axios.get(
  'https://api.breakblocks.com/api/v0.1/servers/find?limit=10',
  {
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    }
  }
);

console.log(response.data);