Skip to main content

Getting Started

This guide will walk you through your first integration with the Moitribe PHP SDK. You'll learn how to initialize the SDK and make your first API call.

Prerequisites

Before you begin, make sure you have:

Basic Initialization

1. Import the SDK

<?php
require_once 'vendor/autoload.php';

use Veniso\Moitribe\Sdk\modules\classes\MoitribeApi;

2. Initialize the SDK

Create a new instance of MoitribeApi with your configuration:

$params = [
'gameid' => 'your-game-id', // Your Moitribe Game ID
'channelid' => 'your-channel-id', // Your Moitribe Channel ID
'playerid' => 'player-123', // Current player's ID
'locale' => 'en-US' // Player's locale (optional)
];

$moitribe = new MoitribeApi($params);

3. Get Player Profile

After initialization, you can access the player's profile:

$profile = $moitribe->getProfile();

if ($profile) {
echo "Player: " . $profile->getName() . "\n";
echo "ID: " . $profile->getId() . "\n";
}

Your First API Call

Let's get the list of available tournaments for your game:

try {
$tournaments = $moitribe->tournRequestsHandler->getTournaments('your-game-id');

echo "Found " . count($tournaments) . " tournaments:\n";

foreach ($tournaments as $tournament) {
echo "- " . $tournament->getName() . " (ID: " . $tournament->getId() . ")\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}

Complete Example

Here's a complete working example:

<?php
require_once 'vendor/autoload.php';

use Veniso\Moitribe\Sdk\modules\classes\MoitribeApi;

try {
// Initialize SDK
$moitribe = new MoitribeApi([
'gameid' => 'your-game-id',
'channelid' => 'your-channel-id',
'playerid' => 'player-123',
'locale' => 'en-US'
]);

// Get player profile
$profile = $moitribe->getProfile();
if ($profile) {
echo "Welcome, " . $profile->getName() . "!\n";
}

// Get tournaments
$tournaments = $moitribe->tournRequestsHandler->getTournaments('your-game-id');
echo "Available tournaments: " . count($tournaments) . "\n";

// Join first tournament if available
if (!empty($tournaments)) {
$firstTournament = $tournaments[0];
$result = $moitribe->tournRequestsHandler->joinTournament(
'your-game-id',
$firstTournament->getId()
);

if ($result > 0) {
echo "Successfully joined tournament: " . $firstTournament->getName() . "\n";
}
}

} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}

SDK Components

The SDK provides several handlers for different features:

// Tournament operations
$moitribe->tournRequestsHandler->getTournaments($gameId);
$moitribe->tournRequestsHandler->joinTournament($gameId, $tournamentId);
$moitribe->tournRequestsHandler->submitTournamentScore($gameId, $tournamentId, $score);

// Group tournament operations
$moitribe->groupTournRequestsHandler->getGroupTournaments($gameId);
$moitribe->groupTournRequestsHandler->joinGroupTournament($gameId, $tournamentId);

// Leaderboard operations
$moitribe->leaderboardRequestsHandler->getLeaderboards($gameId);
$moitribe->leaderboardRequestsHandler->submitScore($gameId, $leaderboardId, $score);

// Profile operations
$moitribe->profRequestsHandler->playerForceLoginWithUniqueId($uniqueId, $channel, $userDetails);
$moitribe->profRequestsHandler->updatePlayerInfo($userDetails);

// Feed operations
$moitribe->feedRequestsHandler->getFeed($playerId);

Configuration Options

Required Parameters

  • gameid - Your Moitribe Game ID
  • channelid - Your Moitribe Channel ID
  • playerid - Current player's unique identifier

Optional Parameters

  • locale - Player's locale (e.g., 'en-US', 'fr-FR')
  • doInit - Whether to perform initialization request (default: true)

Disabling Auto-Initialization

If you want to initialize manually:

$moitribe = new MoitribeApi($params, false); // Don't auto-initialize

// Initialize later when ready
$moitribe->init();

Error Handling

Always wrap your SDK calls in try-catch blocks:

try {
$result = $moitribe->tournRequestsHandler->joinTournament($gameId, $tournamentId);
echo "Success! Result: " . $result;
} catch (InvalidArgumentException $e) {
echo "Invalid parameters: " . $e->getMessage();
} catch (Exception $e) {
echo "API error: " . $e->getMessage();
}

Next Steps

Now that you have the basics working:

  1. Authentication - Learn about player login and profiles
  2. Tournaments - Implement tournament features
  3. Leaderboards - Add competitive leaderboards
  4. Error Handling - Handle common issues

Need Help?

  • Check the Error Handling Guide for common issues
  • Review specific feature documentation for detailed examples
  • Contact Moitribe support for API access issues