Coder Social home page Coder Social logo

sportmonks-football-api's Introduction

Sportmonks Football API PHP Client

PHP Library for Sportmonks Soccer API v3. Developed by Carsten Tetzlaff. This Library is heavily inspired by https://github.com/joesaunderson/sportmonks-soccer.

Prerequisites

PHP >= 7.3

Installation

composer require tetzilla/sportmonks-football-api

Setup

The API Client relies on Environment variables for configuration (setting API token & timezone).

Prerequisites

PHP >= 7.3

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://docs.sportmonks.com/football/welcome/authentication
SPORTMONKS_API_TOKEN=_YOUR_API_TOKEN_HERE

# TIMEZONE (Optional)
# https://docs.sportmonks.com/football/tutorials-and-guides/tutorials/introduction/set-your-time-zone
SPORTMONKS_TIMEZONE=Europe/London

Usage

use Sportmonks\Football\FootballApi;

...

// Basic API call for all Bookmakers
$response = FootballApi::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:

Pagination

// API call for Fixtures with page specified
$response = FootballApi::fixtures()
    ->setPage(3)
    ->getByDate('2023-03-19');

Note: The pagination ($response['pagination']) can be used to loop through pages and build a result set.

Includes

// API call for Fixtures with includes
$response = FootballApi::fixtures()
    ->setInclude(['scores', 'lineups', 'events'])
    ->getByDate('2023-03-19');

Filtering

Entity filter
// API call for Fixtures with filters
$response = FootballApi::fixtures()
    ->setInclude(['events','statistics.type'])
    ->setFilters(['eventTypes' => [18,14]])
    ->getByDate('2023-03-19');
Deleted filter
// API call for Fixtures with deleted filter
$response = FootballApi::fixtures()
    ->setFilters(['deleted'])
    ->all();
Populate filter
// API call for Fixtures with populate (1000 per page)
$response = FootballApi::fixtures()
    ->setFilters(['populate'])
    ->all();

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

Livescores

$response = FootballApi::livescores()->all();
Get all inplay - View Sportmonks Docs
$response = FootballApi::livescores()->inplay();
$response = FootballApi::livescores()->latest();

Fixtures

$response = FootballApi::fixtures()->all();
$response = FootballApi::fixtures()->getById($fixtureId);
Get by multiple ids - View Sportmonks Docs
$response = FootballApi::fixtures()->getByMultipleIds([$fixtureId1,$fixtureIds2,...]);
Get by date - View Sportmonks Docs
$response = FootballApi::fixtures()->getByDate($date);
Get by date range - View Sportmonks Docs
$response = FootballApi::fixtures()->getByDateRange($dateFrom, $dateTo);
Get by date range for team - View Sportmonks Docs
$response = FootballApi::fixtures()->getByDateRangeForTeam($dateFrom, $dateTo, $teamId);
Get by head to head - View Sportmonks Docs
$response = FootballApi::fixtures()->getHeadToHead($teamId1, $teamId2);
Get upcoming by market id - View Sportmonks Docs
$response = FootballApi::fixtures()->getUpcommingByMarketId($marketId);
Get by search by name - View Sportmonks Docs
$response = FootballApi::fixtures()->search($searchQuery);
Get last updated - View Sportmonks Docs
$response = FootballApi::fixtures()->getLastUpdated();

States

Get all states - View Sportmonks Docs

$response = FootballApi::states()->all();
$response = FootballApi::states()->getById();

Leagues

$response = FootballApi::leagues()->all();
$response = FootballApi::leagues()->getById($leagueId);
Get by live - View Sportmonks Docs
$response = FootballApi::leagues()->live();
Get by fixture date - View Sportmonks Docs
$response = FootballApi::leagues()->getByFixtureDate($date);
Get by country id- View Sportmonks Docs
$response = FootballApi::leagues()->getByCountryId($countryId);
Get by search by name - View Sportmonks Docs
$response = FootballApi::leagues()->search($searchQuery);
Get all by team id - View Sportmonks Docs
$response = FootballApi::leagues()->getAllByTeamId($teamId);
Get current by team id - View Sportmonks Docs
$response = FootballApi::leagues()->getCurrentByTeamId($teamId);

Seasons

$response = FootballApi::season()->all();
$response = FootballApi::season()->getById($seasonId);
Get by team id - View Sportmonks Docs
$response = FootballApi::season()->getByTeamId($teamId);
Get by search by name - View Sportmonks Docs
$response = FootballApi::season()->search($searchQuery);

Schedules

Get by season id - View Sportmonks Docs
$response = FootballApi::schedules()->bySeasonId($seasonId);
Get by season id - View Sportmonks Docs
$response = FootballApi::schedules()->byTeamId($teamId);
Get by season id and team id - View Sportmonks Docs
$response = FootballApi::schedules()->bySeasonAndTeamId($seasonId, $teamId);

Stages

$response = FootballApi::stages()->all();
$response = FootballApi::stages()->getById($stageId);
Get by season id - View Sportmonks Docs
$response = FootballApi::stages()->getBySeasonId($seasonId);
Get by search by name - View Sportmonks Docs
$response = FootballApi::stages()->search($searchQuery);

Rounds

$response = FootballApi::rounds()->all();
$response = FootballApi::rounds()->getById($roundId);
Get by season id - View Sportmonks Docs
$response = FootballApi::rounds()->getBySeasonId($seasonId);
Get by search by name - View Sportmonks Docs
$response = FootballApi::rounds()->search($searchQuery);

Standings

$response = FootballApi::standings()->all();
$response = FootballApi::standings()->getBySeasonId($seasonId);
Get by round id - View Sportmonks Docs
$response = FootballApi::standings()->getByRoundId($roundId);
Get corrections by season id - View Sportmonks Docs
$response = FootballApi::standings()->getCorrectionsBySeasonId($seasonId);
Get live standings by league id - View Sportmonks Docs
$response = FootballApi::standings()->getLiveByLeagueId($leagueId);

Topscorers

Get all by season id - View Sportmonks Docs

$response = FootballApi::topscorers()->getBySeasonId($seasonId);

Get all by stage id - View Sportmonks Docs

$response = FootballApi::topscorers()->getByStageId($stageId);

Teams

$response = FootballApi::teams()->all();
$response = FootballApi::teams()->getById($teamId);

Get by country id - View Sportmonks Docs

$response = FootballApi::teams()->getByCountryId($countryId);

Get by season id - View Sportmonks Docs

$response = FootballApi::teams()->getBySeasonId($seasonId);

Get by search by name - View Sportmonks Docs

$response = FootballApi::teams()->search($searchQuery);

Team Squads

Get by team id - View Sportmonks Docs

$response = FootballApi::teamSquads()->getByTeamId($teamId);

Get by team id and season id - View Sportmonks Docs

$response = FootballApi::teamSquads()->getByTeamAndSeasonId($teamId,$seasonId);

Players

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

Get by country id - View Sportmonks Docs

$response = FootballApi::players()->getByCountryId($countryId);

Get by search by name - View Sportmonks Docs

$response = FootballApi::players()->search($searchQuery);

Get last updated - View Sportmonks Docs

$response = FootballApi::players()->getLastUpdated();

Coaches

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

Get by country id - View Sportmonks Docs

$response = FootballApi::coaches()->getByCountryId($countryId);

Get by search by name - View Sportmonks Docs

$response = FootballApi::coaches()->search($searchQuery);

Get last updated - View Sportmonks Docs

$response = FootballApi::coaches()->getLastUpdated();

Referees

$response = FootballApi::referees()->all();
$response = FootballApi::referees()->getById($refereeId);

Get by country id - View Sportmonks Docs

$response = FootballApi::referees()->getByCountryId($countryId);

Get by season id - View Sportmonks Docs

$response = FootballApi::referees()->getBySeasonId($countryId);

Get by search by name - View Sportmonks Docs

$response = FootballApi::referees()->search($searchQuery);

Transfers

$response = FootballApi::transfers()->all();
$response = FootballApi::transfers()->getById($transferId);
$response = FootballApi::transfers()->latest();

Get between date range - View Sportmonks Docs

$response = FootballApi::transfers()->getByDateRange($dateFrom,$dateTo);

Get by team id - View Sportmonks Docs

$response = FootballApi::transfers()->getByTeamId($teamId);

Get by player id - View Sportmonks Docs

$response = FootballApi::transfers()->getByPlayerId($playerId);

Venues

$response = FootballApi::venues()->all();
$response = FootballApi::venues()->getById($venueId);

Get by season id - View Sportmonks Docs

$response = FootballApi::venues()->getBySeasonId($seasonId);

Get by search by name - View Sportmonks Docs

$response = FootballApi::venues()->search($searchQuery);

TV Stations

$response = FootballApi::tvStations()->all();
$response = FootballApi::tvStations()->getById($stationId);

Get by fixture id - View Sportmonks Docs

$response = FootballApi::tvStations()->getByFixtureId($fixtureId);

Predictions

Get predictability - View Sportmonks Docs

$response = FootballApi::predictions()->probabilities();

Get predictability by league id - View Sportmonks Docs

$response = FootballApi::predictions()->getPredictabilityByLeagueId($leagueId);

Get predictability by fixture id - View Sportmonks Docs

$response = FootballApi::tvStations()->getPredictabilityByFixtureId($fixtureId);

Get value bets - View Sportmonks Docs

$response = FootballApi::tvStations()->valueBets();

Pre-match Odds

$response = FootballApi::preMatchOdds()->all();

Get by fixture id - View Sportmonks Docs

$response = FootballApi::preMatchOdds()->getByFixtureId($fixtureId);

Get by fixture id and bookmaker id - View Sportmonks Docs

$response = FootballApi::preMatchOdds()->getByFixtureAndBookmakerId($fixtureId,$bookmakerId);

Get by fixture id and market id - View Sportmonks Docs

$response = FootballApi::preMatchOdds()->getByFixtureAndMarketId($fixtureId,$marketId);

Get last updated - View Sportmonks Docs

$response = FootballApi::preMatchOdds()->getLastUpdated();

Inplay Odds

$response = FootballApi::inplayOdds()->all();

Get by fixture id - View Sportmonks Docs

$response = FootballApi::inplayOdds()->getByFixtureId($fixtureId);

Get by fixture id and bookmaker id - View Sportmonks Docs

$response = FootballApi::inplayOdds()->getByFixtureAndBookmakerId($fixtureId,$bookmakerId);

Get by fixture id and market id - View Sportmonks Docs

$response = FootballApi::inplayOdds()->getByFixtureAndMarketId($fixtureId,$marketId);

Get last updated - View Sportmonks Docs

$response = FootballApi::inplayOdds()->getLastUpdated();

Markets

$response = FootballApi::markets()->all();

Get by market id - View Sportmonks Docs

$response = FootballApi::markets()->getById($marketId);

Get by search - View Sportmonks Docs

$response = FootballApi::markets()->search($searchQuery);

Bookmakers

$response = FootballApi::bookmakers()->all();

Get by bookmaker id - View Sportmonks Docs

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

Get by search - View Sportmonks Docs

$response = FootballApi::bookmakers()->search($searchQuery);

Get by market id - View Sportmonks Docs

$response = FootballApi::bookmakers()->getByFixtureId($fixtureId);

News

Get pre-match news - View Sportmonks Docs

$response = FootballApi::preMatchNews()->all();

Get by season id - View Sportmonks Docs

$response = FootballApi::preMatchNews()->getBySeasonId($seasonId);

Get pre-match news for upcoming fixtures - View Sportmonks Docs

$response = FootballApi::preMatchNews()->upcomingFixtures();

Rivals

Get all rivales - View Sportmonks Docs

$response = FootballApi::rivals()->all();

Get by team id - View Sportmonks Docs

$response = FootballApi::rivals()->getByTeamId($teamId);

Commentaries

Get all commentaries - View Sportmonks Docs

$response = FootballApi::commentaries()->all();

Get by team id - View Sportmonks Docs

$response = FootballApi::commentaries()->getByFixtureId($fixtureId);

Core Endpoints

Core contains all endpoints that are used in all sports.

Continents 🗺️

Get all continents - View Sportmonks Docs

$response = FootballApi::continents()->all();
$response = FootballApi::continents()->getById();

Countries

Get all countries - View Sportmonks Docs

$response = FootballApi::countries()->all();
$response = FootballApi::countries()->getById();

Get by search - View Sportmonks Docs

$response = FootballApi::countries()->search($searchQuery);

Regions

Get all regions - View Sportmonks Docs

$response = FootballApi::regions()->all();
$response = FootballApi::regions()->getById();

Get by search - View Sportmonks Docs

$response = FootballApi::regions()->search($searchQuery);

Cities 🏙️

Get all cities - View Sportmonks Docs

$response = FootballApi::cities()->all();
$response = FootballApi::cities()->getById();

Get by search - View Sportmonks Docs

$response = FootballApi::cities()->search($searchQuery);

Types ⌨️

Get all types - View Sportmonks Docs

$response = FootballApi::types()->all();
$response = FootballApi::types()->getById();

Get by Entity - View Sportmonks Docs

$response = FootballApi::types()->getByEntity();

Filters ⚙️

Get all entity - View Sportmonks Docs

$response = FootballApi::filters()->entity();

My Sportmonks

Retrieve information about your subscription.

Get my enrichments - View Sportmonks Docs

$response = FootballApi::my()->enrichments();

Get my resources - View Sportmonks Docs

$response = FootballApi::my()->resources();

Get my leagues - View Sportmonks Docs

$response = FootballApi::my()->leagues();

License

MIT

sportmonks-football-api's People

Contributors

dependabot[bot] avatar kashmiry avatar tetzilla avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

sportmonks-football-api's Issues

Could not find a matching version of package crt79/sportmonks-football-api

Hello,
When I tried to run composer require pyaesoneaung/sportmonks-football-api
I get this error in the command line:

[InvalidArgumentException]                                                   
Could not find a matching version of package crt79/sportmonks-football-api.
Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.