> ## Documentation Index
> Fetch the complete documentation index at: https://docs.msgaming247.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Documentation

> Integrate Stock games into your platform with our comprehensive API

<Info>
  For partner API requirements and webhook implementations, visit the [Web Hooks](/web-hooks/) page.
</Info>

## Overview

Stock provides a comprehensive game integration API that allows third-party vendors to seamlessly integrate our games into their websites. This documentation outlines the simple integration process for accessing and displaying our games through iframe embedding.

## Getting Started

To integrate Stock games into your platform, you'll need:

* A base URL provided by Stock
* An authorization token for API access

## Authentication

All API requests must include an authorization token in the request headers. This token will be manually provided by Stock during the onboarding process.

<CodeGroup>
  ```bash Headers
  api-key: YOUR_AUTHORIZATION_TOKEN
  ```
</CodeGroup>

## Game Integration Flow

### Step 1: Request Game URL

To access any game, make a POST request to the external user endpoint:

<CodeGroup>
  ```bash Request
  POST {BASE_URL}/api/external-user/
  api-key: YOUR_AUTHORIZATION_TOKEN
  Content-Type: application/json
  ```

  ```json Request Body
  {
    "gameName": "aviator",    // Game identifier (see available games below)
    "name": "John Doe",       // Player's display name  
    "userId": "user_12345"    // Unique user identifier from your system
  }
  ```
</CodeGroup>

**Body Parameters**

<ParamField body="gameName" type="string" required>
  Game identifier from the available games list
</ParamField>

<ParamField body="name" type="string" required>
  Player's display name
</ParamField>

<ParamField body="userId" type="string" required>
  Unique user identifier from your system
</ParamField>

### Step 2: Receive Game URL

<CodeGroup>
  ```json Response
  {
    "url": "https://game-url-here.com"
  }
  ```
</CodeGroup>

### Step 3: Embed Game

Use the returned URL to embed the game in your frontend as an iframe:

<CodeGroup>
  ```html HTML Implementation
  <iframe 
    src="RECEIVED_GAME_URL" 
    width="100%" 
    height="600px"
    frameborder="0">
  </iframe>
  ```

  ```javascript JavaScript Example
  // Example integration code
  async function loadStockGame(gameName, playerName, playerId) {
    try {
      const response = await fetch('{BASE_URL}/api/external-user/', {
        method: 'POST',
        headers: {
          'api-key': 'YOUR_AUTHORIZATION_TOKEN',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          gameName: gameName,
          name: playerName,
          userId: playerId
        })
      });
      
      const data = await response.json();
      
      // Embed game in iframe
      const iframe = document.createElement('iframe');
      iframe.src = data.url;
      iframe.width = '100%';
      iframe.height = '600px';
      iframe.frameBorder = '0';
      
      // Add iframe to your game container
      document.getElementById('game-container').appendChild(iframe);
      
    } catch (error) {
      console.error('Error loading Stock game:', error);
    }
  }

  // Usage example
  loadStockGame('aviator', 'John Doe', 'user_12345');
  ```
</CodeGroup>

## Available Games

Stock offers the following games for integration:

| Game Name        | API Identifier     | Description                          |
| :--------------- | :----------------- | :----------------------------------- |
| Derby            | `derby`            | Horse racing simulation game         |
| Stock Slots      | `stock_slots`      | Stock market themed slot machine     |
| Stock Jackpot    | `stock_jackpot`    | Progressive jackpot with stock theme |
| Seven Up Down    | `seven_up_down`    | Prediction-based card game           |
| Head Tail        | `head_tail`        | Classic coin flip game               |
| Wheel of Fortune | `wheel_of_fortune` | Spinning wheel luck game             |
| Aviator          | `aviator`          | Flight-based multiplier game         |
| Dice             | `dice`             | Traditional dice rolling game        |

## Integration Requirements

<CardGroup cols={2}>
  <Card title="iframe Support" icon="window-maximize">
    Ensure your website can display iframes
  </Card>

  <Card title="Error Handling" icon="triangle-exclamation">
    Implement proper error handling for API requests
  </Card>

  <Card title="Token Management" icon="key">
    Store and securely manage your authorization token
  </Card>

  <Card title="Data Validation" icon="shield-check">
    Validate user data before sending requests
  </Card>
</CardGroup>

## Security Considerations

<Warning>
  Keep your authorization token secure and never expose it in client-side code
</Warning>

<CardGroup cols={2}>
  <Card title="User Authentication" icon="user-shield">
    Implement proper user authentication on your platform
  </Card>

  <Card title="HTTPS Required" icon="lock">
    Ensure HTTPS is used for all API communications
  </Card>
</CardGroup>

## Support

<Tip>
  For technical support, integration assistance, or to obtain your base URL and authorization token, please contact the Stock Games integration team.
</Tip>
