Skip to main content
All RaidHub API endpoints return data wrapped in a standardized RaidHubResponse format. This consistent structure makes it easy to handle both successful and error responses uniformly across your application.

Response Structure

The RaidHubResponse is a discriminated union that can represent either a successful response or an error response, differentiated by the success field.

Success Response

When a request succeeds, the response follows this structure:
minted
string
required
ISO 8601 timestamp indicating when the response was generated
success
boolean
required
Always true for successful responses
response
object
required
The actual response data. The structure varies by endpoint.

Example Success Response

{
  "minted": "2024-03-15T14:32:18.000Z",
  "success": true,
  "response": {
    "membershipId": "4611686018488107374",
    "bungieGlobalDisplayName": "Newo",
    "bungieGlobalDisplayNameCode": "9010",
    "displayName": "xx_newo_xx",
    "iconPath": "/common/destiny2_content/icons/93844c8b76ea80683a880479e3506980.jpg",
    "membershipType": 3,
    "lastSeen": "2021-05-01T00:00:00.000Z",
    "isPrivate": false,
    "cheatLevel": 0
  }
}

Error Response

When a request fails, the response follows this structure:
minted
string
required
ISO 8601 timestamp indicating when the error response was generated
success
boolean
required
Always false for error responses
code
string
required
The error code identifying the type of error. See Error Handling for all error codes.
error
object
required
Additional error details. The structure varies by error code.

Example Error Response

{
  "minted": "2024-03-15T14:32:18.000Z",
  "success": false,
  "code": "PlayerNotFoundError",
  "error": {
    "message": "Player not found"
  }
}

Handling Responses

To handle RaidHub API responses in your code, check the success field:
const response = await fetch('https://api.raidhub.io/player/4611686018488107374/basic', {
  headers: {
    'x-api-key': 'your-api-key'
  }
});

const data = await response.json();

if (data.success) {
  // Handle successful response
  console.log('Player data:', data.response);
} else {
  // Handle error response
  console.error(`Error ${data.code}:`, data.error);
}
The minted timestamp is included in all responses and indicates when the response was generated by the RaidHub API. This can be useful for debugging, caching, or understanding data freshness.

Type Safety

For TypeScript users, the RaidHubResponse is defined as:
type RaidHubResponse<T> = 
  | {
      minted: string; // ISO 8601 date-time
      success: true;
      response: T;
    }
  | {
      minted: string; // ISO 8601 date-time
      success: false;
      code: ErrorCode;
      error: unknown;
    };
This discriminated union type allows TypeScript to narrow the type based on the success field, providing excellent autocomplete and type safety.

Build docs developers (and LLMs) love