PHP Library for Sportmonks Soccer API. Developed by Joe Saunderson.
PHP >= 7.3
composer require joesaunderson/sportmonks-soccer
The API Client relies on Environment variables for configuration (setting API token & timezone).
Install:
composer require symfony/dotenv
Usage:
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
An example .env file:
# API TOKEN (Required)
# https://sportmonks.com/settings#/api
SPORTMONKS_API_TOKEN=_YOUR_API_TOKEN_HERE
# TIMEZONE (Optional)
# https://sportmonks.com/docs/football/2.0/getting-started/a/setting-the-timezone/82
SPORTMONKS_TIMEZONE=Europe/London
use Sportmonks\Soccer\SoccerApi;
...
// Basic API call for all Bookmakers
$response = SoccerApi::bookmakers()->getAll();
The Sportmonks API allows for advanced filtering and sorting, as well as adding data via relationships. This client supports the following:
// API call for Fixtures with includes
$response = SoccerApi::fixtures()
->setIncludes(['goals', 'flatOdds:filter(bookmaker_id|2)'])
->getByDate('2019-05-28');
// API call for Fixtures with page specified
$response = SoccerApi::fixtures()
->setPage(3)
->getByDate('2019-05-28');
Note: The pagination meta ($response['meta']['pagination']
) can be used to loop through pages and build a result set.
Certain endpoints allow for data to be passed as URI query parameters, these are shown below & must be added before the ->get..() call.
->setBookmakers([1, 2])
->setFixtures([1, 2])
->setLeagues([1, 2])
->setMarkets([1, 2])
Note: This client will not validate the usage for the correct endpoints and will not throw an error. Refer to the Sportmonks docs to see which endpoints support the above parameters.
$response = SoccerApi::bookmakers()->getAll();
$response = SoccerApi::bookmakers()->getById($bookmakerId);
$response = SoccerApi::coaches()->getById($coachId);
$response = SoccerApi::commentaries()->getByFixtureId($fixtureId);
$response = SoccerApi::continents()->getAll();
$response = SoccerApi::continents()->getById($continentId);
$response = SoccerApi::countries()->getAll();
$response = SoccerApi::countries()->getById($countryId);
$response = SoccerApi::fixtures()->getById($fixtureId);
$response = SoccerApi::fixtures()->getByDate($date);
$response = SoccerApi::fixtures()->getByDateRange($dateFrom, $dateTo);
$response = SoccerApi::fixtures()->getByDateRangeForTeam($dateFrom, $dateTo, $teamId);
$response = SoccerApi::fixtures()->getByMultipleIds([$fixtureId1, $fixtureId2...]);
$response = SoccerApi::fixtures()->getLastUpdated();
$response = SoccerApi::head2head()->getByTeamIds($team1Id, $team2Id);
$response = SoccerApi::leagues()->getAll();
$response = SoccerApi::leagues()->getById($legueId);
$response = SoccerApi::liveScores()->getAll();
$response = SoccerApi::liveScores()->getAllInPlay();
$response = SoccerApi::markets()->getAll();
$response = SoccerApi::markets()->getById($marketId);
$response = SoccerApi::odds()->getByFixtureAndBookmaker($fixtureId, $bookmakerId);
$response = SoccerApi::odds()->getByFixtureAndMarket($fixtureId, $marketId);
$response = SoccerApi::odds()->getByFixtureId($fixtureId);
$response = SoccerApi::odds()->getInPlayByFixtureId($fixtureId);
$response = SoccerApi::players()->getById($playerId);
$response = SoccerApi::predictions()->getLeagues()
$response = SoccerApi::predictions()->getProbabilities()
$response = SoccerApi::predictions()->getProbabilitiesByFixtureId($fixtureId)
$response = SoccerApi::predictions()->getValueBets()
$response = SoccerApi::predictions()->getValueBetsByFixtureId($fixtureId)
$response = SoccerApi::rounds()->getById($roundId);
$response = SoccerApi::rounds()->getBySeasonId($seasonId);
$response = SoccerApi::seasons()->getAll();
$response = SoccerApi::seasons()->getById($seasonId);
$response = SoccerApi::stages()->getById($stageId);
$response = SoccerApi::stages()->getBySeasonId($seasonId);
$response = SoccerApi::standings()->getBySeasonId($seasonId);
$response = SoccerApi::standings()->getLiveStandingsBySeasonId($seasonId);
$response = SoccerApi::teams()->getById($teamId);
$response = SoccerApi::teams()->getBySeasonId($seasonId);
$response = SoccerApi::teamSquads()->getByTeamAndSeason($teamId, $seasonId);
$response = SoccerApi::topScorers()->getBySeasonId($seasonId);
$response = SoccerApi::topScorers()->getAggregatedBySeasonId($seasonId);
$response = SoccerApi::tvStations()->getByFixtureId($fixtureId);
$response = SoccerApi::venues()->getById($venueId);
$response = SoccerApi::venues()->getBySeasonId($seasonId);
$response = SoccerApi::videoHighlights()->getAll();