Skip to content

joesaunderson/sportmonks-soccer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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

$response = SoccerApi::bookmakers()->getAll();
$response = SoccerApi::bookmakers()->getById($bookmakerId);

Coaches

$response = SoccerApi::coaches()->getById($coachId);

Commentaries

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

Continents

$response = SoccerApi::continents()->getAll();
$response = SoccerApi::continents()->getById($continentId);

Countries

$response = SoccerApi::countries()->getAll();
$response = SoccerApi::countries()->getById($countryId);

Fixtures

$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...]);
Get Last Updated - View Sportmonks Docs
$response = SoccerApi::fixtures()->getLastUpdated();

Head2Head

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

Leagues

$response = SoccerApi::leagues()->getAll();
$response = SoccerApi::leagues()->getById($legueId);

Live Scores

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

Markets

$response = SoccerApi::markets()->getAll();
$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

$response = SoccerApi::players()->getById($playerId);

Predictions

$response = SoccerApi::predictions()->getLeagues()
Get Probabilities View Sportmonks Docs
$response = SoccerApi::predictions()->getProbabilities()
Get Probabilities By Fixture Id View Sportmonks Docs
$response = SoccerApi::predictions()->getProbabilitiesByFixtureId($fixtureId)
Get Value Bets View Sportmonks Docs
$response = SoccerApi::predictions()->getValueBets()
Get Value Bets By Fixture Id View Sportmonks Docs
$response = SoccerApi::predictions()->getValueBetsByFixtureId($fixtureId)

Rounds

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

Seasons

$response = SoccerApi::seasons()->getAll();
$response = SoccerApi::seasons()->getById($seasonId);

Stages

$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

$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

$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

About

PHP API Client for Sportmonks Soccer API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages