# Competition Engine — External Casino API # OpenAPI 3.0.3 — Incoming API calls used by external casino systems # # Source files inspected: # - config/routes.rb (lines 54-69, api namespace) # - app/controllers/api/api_controller.rb # - app/controllers/api/customers_controller.rb # - app/controllers/api/labels_controller.rb # - app/controllers/api/customer_labels_controller.rb # - app/controllers/api/competitions/participants_controller.rb # - app/controllers/api/competitions/leaderboards_controller.rb # - config/routes.rb (full route listing) # # NOTE: This spec documents the API as it currently exists. # Standard serializer responses use status: success/failure. Some controller-specific # errors use a success: false envelope. openapi: "3.0.3" info: title: "Competition Engine — External Casino API" version: "1.0.0" description: | REST API endpoints for external casino systems to send events and manage reference data in the Competition Engine. All endpoints authenticate via the `X-API-KEY` header. tags: - name: Customers description: Customer management (upsert by external ID) - name: Labels description: Label definition management - name: Customer Labels description: Customer-to-label association management - name: Participants description: Competition participant opt-in - name: Leaderboard description: Leaderboard queries - name: Events description: Casino runtime event ingestion servers: - url: "https://{host}/api/env/{env_name}" description: Production API server variables: host: default: "api.competition-engine.example.com" description: Competition Engine host env_name: default: "your_environment" description: Environment name (e.g., "casino_prod") paths: /customers/upsert: post: operationId: upsertCustomer summary: Create or update a customer by external ID description: > Creates a new customer or updates an existing one identified by `external_id`. This is the primary endpoint for synchronizing customer data from the casino system into the Competition Engine. tags: - Customers parameters: - $ref: "#/components/parameters/EnvName" security: - ApiKeyAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CustomerUpsertRequest" example: external_id: 987654 name: "John Doe" responses: "200": description: Customer was created or updated content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "Customer updated" data: id: 42 external_id: 987654 name: "John Doe" "500": $ref: "#/components/responses/InternalError" /labels/sync: put: operationId: syncLabels summary: Sync label definitions description: > Creates or updates labels by their `external_id`. Existing labels are updated; new labels are created. This endpoint replaces the full set of labels with each call. tags: - Labels parameters: - $ref: "#/components/parameters/EnvName" security: - ApiKeyAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LabelSyncRequest" example: labels: - external_id: "vip_gold" name: "VIP Gold" - external_id: "vip_platinum" name: "VIP Platinum" responses: "200": description: Labels synced successfully content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "Label(s) updated" data: {} "500": $ref: "#/components/responses/InternalError" /customer_labels/sync: put: operationId: syncCustomerLabels summary: Sync label-to-customer associations description: > Associates a set of labels with a customer. Pass an empty `label_external_ids` array to clear all labels from the customer. Non-existent label IDs are silently ignored. tags: - Customer Labels parameters: - $ref: "#/components/parameters/EnvName" security: - ApiKeyAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CustomerLabelSyncRequest" example: customer_external_id: 987654 label_external_ids: - "vip_gold" - "vip_platinum" responses: "200": description: Customer-label associations synced content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "CustomerLabel(s) updated" data: {} "500": $ref: "#/components/responses/InternalError" /competitions/{competition_id}/participants: post: operationId: createParticipant summary: Opt a customer into a competition description: > Registers a customer as a participant in a competition. If the customer is already opted in, returns 202 Accepted with a success message — this is not an error. tags: - Participants parameters: - $ref: "#/components/parameters/EnvName" - name: competition_id in: path required: true schema: type: integer description: Competition ID example: 5 security: - ApiKeyAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ParticipantCreateRequest" example: external_id: 987654 responses: "201": description: Participant created successfully content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "Participant created" data: {} "202": description: Customer was already opted in (idempotent) content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "Participant already opted-in" data: {} "500": $ref: "#/components/responses/InternalError" /competitions/{competition_id}/leaderboard: get: operationId: getLeaderboard summary: Get the current leaderboard for a competition description: > Returns the current leaderboard rankings for a competition. Optionally filter to a specific customer or limit the number of entries. The response structure depends on the competition's scoring strategy (max_points or threshold_reach). tags: - Leaderboard parameters: - $ref: "#/components/parameters/EnvName" - name: competition_id in: path required: true schema: type: integer description: Competition ID example: 5 - name: customer_id in: query required: false schema: type: integer description: Filter to a specific customer by external ID example: 987654 - name: limit in: query required: false schema: type: integer description: Maximum number of leaderboard entries to return example: 100 security: - ApiKeyAuth: [] responses: "200": description: Leaderboard data content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success data: kind: single_stage scoring_strategy: max_points rewards: - value: 100.0 kind: real_money evaluation_value: 1 evaluation_strategy: position contests: - id: 2 name: "Max points" start_date: "2016-11-26T09:34:57.680Z" end_date: "2036-11-26T09:34:57.681Z" threshold: null participants: - contest_id: 2 customer_id: 1 customer_external_id: 987654 customer_name: "John Doe" customer_score: "1500.0" customer_position: 1 "500": $ref: "#/components/responses/InternalError" /events: post: operationId: ingestEvent summary: Submit a casino runtime event for async processing description: > Accepts a casino runtime event (bet settlement, round completion, player action, etc.) for asynchronous processing. Returns 202 Accepted immediately — the event is not evaluated at request time. Check the Competition Engine admin UI for processing status. tags: - Events parameters: - $ref: "#/components/parameters/EnvName" security: - ApiKeyAuth: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/EventIngestRequest" example: event_uuid: "MTAxNDAzX2Nhc2lub193aW5fMjAyNi0wNi0wNFQxMjowMjowNy4yNDYrMDA6MDA=" action: "casino_win" sourceValue: 0.0005 memberRefId: 101403 transactionTimestamp: "2026-06-04T12:02:07.246+00:00" metadata: realMoneyAmount: 0.0072 bonusAmount: 0.0 gameId: "bp-lobby" gameName: "PoolBet lobby" vendorName: "PoolBet" currency: "EUR" roundId: "347359" transaction: "102062_347359_93efe1d1-cf6a-43c5-81ff-a7d14e671cb9" betAmount: 14.62 responses: "202": description: Event accepted for processing content: application/json: schema: $ref: "#/components/schemas/ApiSuccessResponse" example: status: success message: "Event accepted for processing" data: {} "401": description: Unauthorized — missing or invalid X-API-KEY content: application/json: schema: $ref: "#/components/schemas/ApiErrorResponse" example: success: false message: "Unauthorized" "422": description: Validation error — invalid request body content: application/json: schema: $ref: "#/components/schemas/ApiErrorResponse" example: success: false message: "Validation failed: event_uuid is missing" "500": $ref: "#/components/responses/InternalError" components: parameters: EnvName: name: env_name in: path required: true schema: type: string pattern: "^[a-zA-Z0-9_]{3,}$" description: Environment name (e.g., "casino_prod") example: "casino_prod" securitySchemes: ApiKeyAuth: type: apiKey in: header name: X-API-KEY description: > API key assigned to the environment. Used for authentication and tenant resolution. Obtain this key from the Competition Engine admin interface. schemas: CustomerUpsertRequest: type: object description: Request body for creating or updating a customer properties: external_id: type: integer description: External customer ID from the casino system example: 987654 name: type: string description: Customer display name example: "John Doe" required: - external_id - name LabelSyncRequest: type: object description: Request body for syncing label definitions properties: labels: type: array items: $ref: "#/components/schemas/LabelDefinition" required: - labels LabelDefinition: type: object description: A label definition to sync properties: external_id: type: string description: Unique label identifier from the casino system example: "vip_gold" name: type: string description: Human-readable label name example: "VIP Gold" required: - external_id - name CustomerLabelSyncRequest: type: object description: Request body for syncing customer-to-label associations properties: customer_external_id: type: integer description: External ID of the customer example: 987654 label_external_ids: type: array items: type: string description: > List of label external IDs to associate with the customer. An empty array clears all labels. example: - "vip_gold" - "vip_platinum" required: - customer_external_id ParticipantCreateRequest: type: object description: Request body for opting a customer into a competition properties: external_id: type: integer description: External customer ID to register example: 987654 required: - external_id EventIngestRequest: type: object description: Casino runtime event payload for HTTP→RabbitMQ ingestion properties: event_uuid: type: string description: > Unique event ID for deduplication (unique per environment). Accepts UUID-format strings or base64-encoded composite keys. example: "MTAxNDAzX2Nhc2lub193aW5fMjAyNi0wNi0wNFQxMjowMjowNy4yNDYrMDA6MDA=" action: type: string description: Event type identifier (maps to Event.kind) example: "bet_settled" sourceValue: type: number description: Numeric value associated with the event (maps to Event.source_value) example: 150.0 memberRefId: type: integer description: External customer/member ID (maps to Event.customer_external_id) example: 987654 transactionTimestamp: type: string format: date-time description: When the event occurred in the casino system (ISO8601) example: "2026-06-04T12:00:00Z" metadata: type: object nullable: true description: Optional free-form data (maps to Event.data JSONB) example: { "game_id": "blackjack_001", "table_id": "T3" } required: - event_uuid - action - sourceValue - memberRefId - transactionTimestamp ApiSuccessResponse: type: object description: Standard success response envelope properties: status: type: string enum: ["success"] description: Success status example: success message: type: string description: Human-readable result message example: "Customer updated" data: oneOf: - type: object - type: array items: {} description: Response payload (varies by endpoint) example: {} required: - status - data ApiErrorResponse: type: object description: Controller-specific error response envelope properties: success: type: boolean enum: [false] example: false message: type: string description: Human-readable error description example: "Something went wrong" required: - success - message ApiSerializerFailureResponse: type: object description: Standard serializer failure response envelope properties: data: type: object description: Response payload (usually empty) example: {} status: type: string enum: ["failure"] description: Failure status example: failure message: type: string description: Human-readable error description example: "Something went wrong" required: - data - status - message responses: InternalError: description: Internal server error content: application/json: schema: $ref: "#/components/schemas/ApiSerializerFailureResponse" example: status: failure message: "Something went wrong" data: {}