Skip to content
PHP API Client for Sportmonks Soccer API
Branch: master
Clone or download
Latest commit ad6e724 Jun 19, 2019

README.md

Sportmonks Soccer API PHP Client

Build Status

PHP Library for Sportmonks Soccer API. Developed by Joe Saunderson.

Prerequisites

PHP >= 7.3

Installation

composer require joesaunderson/sportmonks-soccer

Setup

The API Client relies on Environment variables for configuration (setting API token & timezone). 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

Usage

use Sportmonks\Soccer\SoccerApi;

...

// Basic API call for all Bookmakers
$response = SoccerApi::bookmakers()->getAll();

Pagination, Filtering, Sorting & Data Enrichment

The Sportmonks API allows for advanced filtering and sorting, as well as adding data via relationships. This client supports the following:

Includes

// API call for Fixtures with includes
$response = SoccerApi::fixtures()
    ->setIncludes(['goals', 'flatOdds:filter(bookmaker_id|2)'])
    ->getByDate('2019-05-28');

Pagination

// 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.

Additional Parameters

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.

Full Endpoint Examples

Bookmakers

Get All - View Sportmonks Docs
$response = SoccerApi::bookmakers()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::bookmakers()->getById($bookmakerId);

Coaches

Get By Id - View Sportmonks Docs
$response = SoccerApi::coaches()->getById($coachId);

Commentaries

Get By Fixture Id - View Sportmonks Docs
$response = SoccerApi::commentaries()->getByFixtureId($fixtureId);

Continents

Get All - View Sportmonks Docs
$response = SoccerApi::continents()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::continents()->getById($continentId);

Countries

Get All - View Sportmonks Docs
$response = SoccerApi::countries()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::countries()->getById($countryId);

Fixtures

Get By Id - View Sportmonks Docs
$response = SoccerApi::fixtures()->getById($fixtureId);
Get By Date - View Sportmonks Docs
$response = SoccerApi::fixtures()->getByDate($date);
Get By Date Range - View Sportmonks Docs
$response = SoccerApi::fixtures()->getByDateRange($dateFrom, $dateTo);
Get By Date Range For Team - View Sportmonks Docs
$response = SoccerApi::fixtures()->getByDateRangeForTeam($dateFrom, $dateTo, $teamId);
Get By Multiple Ids - View Sportmonks Docs
$response = SoccerApi::fixtures()->getByMultipleIds([$fixtureId1, $fixtureId2...]);

Head2Head

Get By Team Ids - View Sportmonks Docs
$response = SoccerApi::head2head()->getByTeamIds($team1Id, $team2Id);

Leagues

Get All - View Sportmonks Docs
$response = SoccerApi::leagues()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::leagues()->getById($legueId);

Live Scores

Get All - View Sportmonks Docs
$response = SoccerApi::liveScores()->getAll();
Get All Inplay - View Sportmonks Docs
$response = SoccerApi::liveScores()->getAllInPlay();

Markets

Get All - View Sportmonks Docs
$response = SoccerApi::markets()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::markets()->getById($marketId);

Odds

Get By Fixture & Bookmaker - View Sportmonks Docs
$response = SoccerApi::odds()->getByFixtureAndBookmaker($fixtureId, $bookmakerId);
Get By Fixture & Market - View Sportmonks Docs
$response = SoccerApi::odds()->getByFixtureAndMarket($fixtureId, $marketId);
Get By Fixture Id - View Sportmonks Docs
$response = SoccerApi::odds()->getByFixtureId($fixtureId);
Get Inplay Odds By Fixture Id - View Sportmonks Docs
$response = SoccerApi::odds()->getInPlayByFixtureId($fixtureId);

Players

Get By Id - View Sportmonks Docs
$response = SoccerApi::players()->getById($playerId);

Rounds

Get By Id - View Sportmonks Docs
$response = SoccerApi::rounds()->getById($roundId);
Get By Season Id - View Sportmonks Docs
$response = SoccerApi::rounds()->getBySeasonId($seasonId);

Seasons

Get All - View Sportmonks Docs
$response = SoccerApi::seasons()->getAll();
Get By Id - View Sportmonks Docs
$response = SoccerApi::seasons()->getById($seasonId);

Stages

Get By Id - View Sportmonks Docs
$response = SoccerApi::stages()->getById($stageId);
Get By Season Id - View Sportmonks Docs
$response = SoccerApi::stages()->getBySeasonId($seasonId);

Standings

Get By Season Id - View Sportmonks Docs
$response = SoccerApi::standings()->getBySeasonId($seasonId);
Get Live Standings - View Sportmonks Docs
$response = SoccerApi::standings()->getLiveStandingsBySeasonId($seasonId);

Teams

Get By Id - View Sportmonks Docs
$response = SoccerApi::teams()->getById($teamId);
Get By Season - View Sportmonks Docs
$response = SoccerApi::teams()->getBySeasonId($seasonId);

Team Squads

Get By Team & Season - View Sportmonks Docs
$response = SoccerApi::teamSquads()->getByTeamAndSeason($teamId, $seasonId);

Top Scorers

Get By Season Id - View Sportmonks Docs
$response = SoccerApi::topScorers()->getBySeasonId($seasonId);
Aggregated By Season Id - View Sportmonks Docs
$response = SoccerApi::topScorers()->getAggregatedBySeasonId($seasonId);

Tv Stations

Get By Fixture Id - View Sportmonks Docs
$response = SoccerApi::tvStations()->getByFixtureId($fixtureId);

Venues

Get By Id - View Sportmonks Docs
$response = SoccerApi::venues()->getById($venueId);
Get By Season Id - View Sportmonks Docs
$response = SoccerApi::venues()->getBySeasonId($seasonId);

Video Highlights

Get By Fixture Id - View Sportmonks Docs
$response = SoccerApi::videoHighlights()->getAll();

License

MIT

You can’t perform that action at this time.