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
- 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:
- Set up your Supabase project locally
- 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
- Validate All Inputs: Always validate API requests
- Log Everything: Comprehensive logging for debugging
- Session Management: Store and validate session keys securely
Performance Optimization
- Async Processing: Use async/await for database operations
- Connection Pooling: Implement database connection pooling
- Caching: Cache frequently accessed data like user details
- 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
Endpoint | Method | Authentication | Purpose |
---|---|---|---|
/start-game | POST | Bearer token | Create game session |
/get-user | GET | NP-API-KEY header | Get user details |
Support and Resources
- Documentation: Client API Reference
- Community: NightPixel Developer Forum
- Support: Contact our integration support team
- Examples: Check our GitHub repository for more examples
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.