LogoNightPixel

Platform Integration Guide

Complete guide for integrating your game with NightPixel's backend services and payment system

Integration Overview

NightPixel provides a comprehensive platform for game developers with secure authentication, token-based payments, and real-time communication capabilities.

API Endpoints

The NightPixel platform provides several API endpoints for game integration:

  • Start Game Session: https://api.nightpixel.com/functions/v1/start-game
  • Get User Details: https://api.nightpixel.com/functions/v1/get-user

Authentication Flow

Starting a Game Session

Games must first establish a session with the NightPixel platform using a user's Bearer token.

Start Game Request

curl -i --location --request POST 'https://api.nightpixel.com/functions/v1/start-game' \
  --header 'Authorization: Bearer your-user-token' \
  --header 'Content-Type: application/json' \
  --data '{
    "game": "your-game-code",
    "redirect_to": "https://your-game-url.com"
  }'

Response

{
  "success": true,
  "session_key": "uuid-session-key",
  "session_id": 123,
  "redirect_url": "https://your-game-url.com?np_game_auth=uuid-session-key"
}

Getting User Information

Once you have a session key, you can retrieve user details using the get-user endpoint.

Get User Request

curl -i --location --request GET 'https://api.nightpixel.com/functions/v1/get-user' \
  --header 'NP-API-KEY: game-auth-key'

Response

{
  "data": {
    "username": "player123",
    "id": "user-unique-id",
    "is_guest": false
  }
}

Error Handling

Common Error Scenarios

  1. Invalid Session Key: Game session not found or expired

Error Response Format

{
  "error": "Error description",
  "details": "Additional error details (optional)"
}

Testing Your Integration

Local Development

Test your integration locally using the provided curl examples. Make sure to:

  1. Set up your Supabase project locally
  2. Test all API endpoints with valid session keys

Integration Checklist

  • Game Session: Start game session and obtain session key
  • User Authentication: Get user details with session key
  • Error Handling: All error scenarios handled gracefully
  • Security: Input validation and HTTPS implemented
  • Testing: All endpoints tested with valid/invalid data

Best Practices

Security Considerations

  1. Validate All Inputs: Always validate API requests
  2. Log Everything: Comprehensive logging for debugging
  3. Session Management: Store and validate session keys securely

Performance Optimization

  1. Async Processing: Use async/await for database operations
  2. Connection Pooling: Implement database connection pooling
  3. Caching: Cache frequently accessed data like user details
  4. Monitoring: Implement health checks and monitoring

Monitoring and Debugging

// Add comprehensive logging
export function logGameEvent(event: string, data: any) {
  console.log(`[GAME] ${event}:`, {
    timestamp: new Date().toISOString(),
    event,
    data: JSON.stringify(data),
  });
}

// Usage in your handlers
logGameEvent("SESSION_STARTED", { user_id, session_key });
logGameEvent("USER_AUTHENTICATED", { user_id, username });

API Reference Summary

EndpointMethodAuthenticationPurpose
/start-gamePOSTBearer tokenCreate game session
/get-userGETNP-API-KEY headerGet user details

Support and Resources


Ready to integrate with NightPixel? Start by implementing the game session flow and setting up your webhook endpoint. For additional help, reach out to our developer support team.