### Example API Request (Leagues Endpoint)
Source: https://api-sports.io/documentation/basketball/v1/index
Demonstrates how to make an API request to the 'leagues' endpoint using various programming languages. Remember to replace 'XxXxXxXxXxXxXxXxXxXxXx' with your actual API key. The API expects GET requests with the 'x-apisports-key' header.
```cURL
curl --location --request GET 'https://v1.basketball.api-sports.io/leagues'
--header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXx'
```
```Python
import requests
url = "https://v1.basketball.api-sports.io/leagues"
headers = {
"x-apisports-key": "XxXxXxXxXxXxXxXxXxXxXx"
}
response = requests.get(url, headers=headers)
print(response.json())
```
```JavaScript
fetch('https://v1.basketball.api-sports.io/leagues', {
method: 'GET',
headers: {
'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXx'
}
})
.then(response => response.json())
.then(data => console.log(data));
```
```PHP
```
--------------------------------
### Fetch Basketball Leagues using cURL
Source: https://api-sports.io/documentation/basketball/v1/index
This command-line example uses cURL to fetch basketball league data. It specifies the GET request method, the target URL, and includes the required 'x-apisports-key' header. This is a simple and direct way to interact with the API from the terminal.
```bash
curl --request GET \
--url https://v1.basketball.api-sports.io/leagues \
--header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx'
```
--------------------------------
### Fetch Basketball Leagues using C and libcurl
Source: https://api-sports.io/documentation/basketball/v1/index
This C code snippet demonstrates how to fetch basketball league data using the libcurl library. It initializes a curl handle, sets the request method to GET, specifies the URL, and adds the necessary 'x-apisports-key' header. Ensure libcurl is installed and linked.
```c
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://v1.basketball.api-sports.io/leagues");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
```
--------------------------------
### Get Player Game Statistics Request Example (PHP)
Source: https://api-sports.io/documentation/basketball/v1/index
This PHP code snippet demonstrates how to make a GET request to the API-SPORTS /games/statistics/players endpoint. It requires an API-SPORTS key in the headers and can accept query parameters like 'id' for a specific game. The client library 'http' is used for making the request and handling the response.
```php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://v1.basketball.api-sports.io/games/statistics/players');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array(
'id' => '391053'
)));
$request->setHeaders(array(
'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
```
--------------------------------
### Fetch Basketball Leagues with PHP Request2
Source: https://api-sports.io/documentation/basketball/v1/index
Fetches basketball league data using the HTTP_Request2 PEAR package in PHP. Requires 'HTTP_Request2' to be installed. Sends a GET request to the leagues endpoint with an API key in the headers, handling redirects and exceptions. Outputs the response body if the status is 200.
```php
setUrl('https://v1.basketball.api-sports.io/leagues');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx',
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
```
--------------------------------
### Custom Translation JSON Example
Source: https://api-sports.io/documentation/basketball/v1/index
Provides an example of the JSON structure for custom translation files. This format allows for overriding default labels, translating missing terms, and adapting terminology for specific audiences. The file must adhere to the internal key structure for proper integration.
```json
{
"all": "All",
"live": "Now Live",
"finished": "Completed",
"scheduled": "Coming Up",
"favorites": "Favorites",
}
```
--------------------------------
### Fetch Basketball Leagues using Javascript jQuery AJAX
Source: https://api-sports.io/documentation/basketball/v1/index
This Javascript example uses jQuery's AJAX method to fetch basketball league data. It configures the request settings with the URL, method (GET), and the 'x-apisports-key' header. The 'done' callback function logs the response upon successful completion.
```javascript
var settings = {
"url": "https://v1.basketball.api-sports.io/leagues",
"method": "GET",
"timeout": 0,
"headers": {
"x-apisports-key": "XxXxXxXxXxXxXxXxXxXxXxXx",
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
```
--------------------------------
### Get Basketball Odds Request Sample (PHP)
Source: https://api-sports.io/documentation/basketball/v1/index
This snippet demonstrates how to make a GET request to the API-SPORTS basketball odds endpoint using PHP. It includes setting query parameters for season, bet, bookmaker, game, and league, along with the necessary API key in the headers.
```php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://v1.basketball.api-sports.io/odds');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array(
'season' => '2019-2020',
'bet' => '1',
'bookmaker' => '6',
'game' => '1912',
'league' => '12'
)));
$request->setHeaders(array(
'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
```
--------------------------------
### Get Standings Request Sample (PHP)
Source: https://api-sports.io/documentation/basketball/v1/index
This PHP code snippet demonstrates how to make a GET request to the API-Sports basketball API to retrieve league standings. It sets the request URL, method, query parameters for league and season, and includes the required 'x-apisports-key' header. The response body is then printed.
```php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://v1.basketball.api-sports.io/standings');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array(
'league' => '12',
'season' => '2019-2020'
)));
$request->setHeaders(array(
'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
```
--------------------------------
### GET /players
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieves a list of players for a given team and season.
```APIDOC
## GET /players
### Description
Retrieves a list of players for a given team and season.
### Method
GET
### Endpoint
https://v1.basketball.api-sports.io/players
### Parameters
#### Query Parameters
- **team** (integer) - Required - The id of the team.
- **season** (string) - Required - The season of the league (e.g., '2023-2024').
### Request Example
```json
{
"query": {
"team": 1,
"season": "2023-2024"
}
}
```
### Response
#### Success Response (200)
- **get** (string) - The endpoint requested.
- **parameters** (object) - The parameters used for the request.
- **errors** (array) - An array of errors, if any.
- **results** (integer) - The number of results returned.
- **response** (array) - An array of player objects.
- **id** (integer) - Player ID.
- **name** (string) - Player name.
- **number** (integer/null) - Player jersey number.
- **country** (string/null) - Player's country.
- **position** (string/null) - Player's position.
- **age** (integer/null) - Player's age.
#### Response Example
```json
{
"get": "players",
"parameters": {
"team": "1",
"season": "2023-2024"
},
"errors": [],
"results": 16,
"response": [
{
"id": 11636,
"name": "B. Newley",
"number": null,
"country": null,
"position": null,
"age": null
},
{
"id": 4,
"name": "Blogg Campbell",
"number": "3",
"country": "Australia",
"position": "Guard",
"age": 20
}
]
}
```
```
--------------------------------
### GET /games
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieves a list of basketball games based on provided query parameters. Requires an API key in the headers.
```APIDOC
## GET /games
### Description
Retrieves a list of basketball games based on provided query parameters such as date, league, season, team, and timezone. Requires an API key in the headers.
### Method
GET
### Endpoint
https://v1.basketball.api-sports.io/games
### Parameters
#### Query Parameters
- **id** (integer) - Optional - The id of the game
- **date** (string) - Optional - YYYY-MM-DD format, e.g., "2019-11-23". A valid date.
- **league** (integer) - Optional - The id of the league.
- **season** (string) - Optional - Format "YYYY" or "YYYY-YYYY", e.g., "2021-2022". The season of the league.
- **team** (integer) - Optional - The id of the team.
- **timezone** (string) - Optional - A valid timezone, e.g., "Europe/London".
#### Header Parameters
- **x-apisports-key** (string) - Required - Your API-SPORTS Key
### Request Example
```json
{
"query": {
"date": "2019-11-23"
},
"headers": {
"x-apisports-key": "YOUR_API_KEY"
}
}
```
### Response
#### Success Response (200)
- **get** (string) - The type of request made.
- **parameters** (object) - The parameters used for the request.
- **errors** (array) - An array of errors, if any.
- **results** (integer) - The number of results returned.
- **response** (array) - An array of game objects.
- **id** (integer) - The game ID.
- **date** (string) - The date and time of the game.
- **time** (string) - The time of the game.
- **timestamp** (integer) - The Unix timestamp of the game.
- **timezone** (string) - The timezone of the game.
- **stage** (string) - The stage of the game (e.g., "Regular Season").
- **week** (string) - The week of the game.
- **venue** (object) - Venue details.
- **status** (object) - Game status details.
- **league** (object) - League details.
- **country** (object) - Country details.
- **teams** (object) - Team details (home and away).
- **scores** (object) - Score details (home and away).
#### Response Example
```json
{
"get": "games",
"parameters": {
"league": "12",
"date": "2019-11-23",
"team": "134",
"timezone": "europe/london",
"season": "2019-2020"
},
"errors": [],
"results": 1,
"response": [
{
"id": 1911,
"date": "2019-11-23T00:30:00+00:00",
"time": "00:30",
"timestamp": 1574469000,
"timezone": "europe/london",
"stage": null,
"week": null,
"venue": null,
"status": {
"long": "Game Finished",
"short": "FT",
"timer": null
},
"league": {
"id": 12,
"name": "NBA",
"type": "League",
"season": "2019-2020",
"logo": null
},
"country": {
"id": 5,
"name": "USA",
"code": "US",
"flag": "https://media.api-sports.io/flags/us.svg"
},
"teams": {
"home": {
"id": 134,
"name": "Brooklyn Nets",
"logo": null
},
"away": {
"id": 157,
"name": "Sacramento Kings",
"logo": null
}
},
"scores": {
"home": {
"quarter_1": 26,
"quarter_2": 30,
"quarter_3": 30,
"quarter_4": 30,
"over_time": null,
"total": 116
},
"away": {
"quarter_1": 23,
"quarter_2": 26,
"quarter_3": 21,
"quarter_4": 27,
"over_time": null,
"total": 97
}
}
}
]
}
```
```
--------------------------------
### GET /leagues
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieve a list of available sports leagues. This endpoint requires an API key for authentication.
```APIDOC
## GET /leagues
### Description
Retrieves a list of available sports leagues. Requires an API key for authentication.
### Method
GET
### Endpoint
/leagues
### Parameters
#### Query Parameters
- **x-apisports-key** (string) - Required - Your API key for authentication.
### Request Example
```
https://v1.basketball.api-sports.io/leagues?x-apisports-key=YOUR_API_KEY
```
### Response
#### Success Response (200)
- **response** (object) - Contains the list of leagues and their details.
- **leagues** (array) - An array of league objects.
- **league.id** (integer) - The unique identifier for the league.
- **league.name** (string) - The name of the league.
- **league.type** (string) - The type of the league (e.g., 'league', 'cup').
- **league.logo** (string) - URL to the league's logo.
- **league.flag** (string) - URL to the league's flag.
- **league.season** (integer) - The current season year.
- **league.coverage** (object) - Information about the league's coverage.
#### Response Example
```json
{
"get": "leagues",
"parameters": [],
"errors": [],
"results": 1,
"paging": {
"current": 1,
"total": 1
},
"response": [
{
"league": {
"id": 1,
"name": "League Name",
"type": "league",
"logo": "http://example.com/logo.png",
"flag": null,
"season": 2023,
"coverage": {
"fixtures": {
"runs": true
},
"standings": true,
"players": true,
"top_scorers": true,
"top_assists": true,
"top_cards": true
}
}
}
]
}
```
```
--------------------------------
### Get Status Endpoint
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieves account and subscription information, including request limits. This call does not count against the daily quota.
```APIDOC
## GET /status
### Description
Retrieves account and subscription information, including current request counts and limits. This endpoint is useful for monitoring API usage and is free to call.
### Method
GET
### Endpoint
https://v1.basketball.api-sports.io/status
### Parameters
#### Query Parameters
None
#### Request Body
None
### Request Example
```bash
curl -X GET "https://v1.basketball.api-sports.io/status" \
-H "x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx"
```
### Response
#### Success Response (200)
- **get** (string) - The name of the endpoint called.
- **parameters** (array) - An empty array for this endpoint.
- **errors** (array) - An empty array if successful.
- **results** (integer) - The number of results, which is 1 for the status endpoint.
- **response** (object) - Contains the account, subscription, and requests details.
- **account** (object) - User account details.
- **firstname** (string) - User's first name.
- **lastname** (string) - User's last name.
- **email** (string) - User's email address.
- **subscription** (object) - User's subscription details.
- **plan** (string) - The name of the subscription plan.
- **end** (string) - The subscription end date and time (ISO 8601 format).
- **active** (boolean) - Indicates if the subscription is active.
- **requests** (object) - Information about API request usage.
- **current** (integer) - The number of requests made so far.
- **limit_day** (integer) - The daily limit for API requests.
#### Response Example
```json
{
"get": "status",
"parameters": [],
"errors": [],
"results": 1,
"response": {
"account": {
"firstname": "xxxx",
"lastname": "XXXXXX",
"email": "xxx@xxx.com"
},
"subscription": {
"plan": "Free",
"end": "2020-04-10T23:24:27+00:00",
"active": true
},
"requests": {
"current": 12,
"limit_day": 100
}
}
}
```
```
--------------------------------
### GET /games
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieves a list of basketball games. Supports filtering by timezone and provides game status information.
```APIDOC
## GET /games
### Description
Retrieves a list of basketball games. You can add the `timezone` query parameter to retrieve games in a specific timezone. The endpoint requires at least one parameter.
**Available Statuses:**
- NS: Not Started
- Q1: Quarter 1 (In Play)
- Q2: Quarter 2 (In Play)
- Q3: Quarter 3 (In Play)
- Q4: Quarter 4 (In Play)
- OT: Over Time (In Play)
- BT: Break Time (In Play)
- HT: Halftime (In Play)
- FT: Game Finished (Game Finished)
- AOT: After Over Time (Game Finished)
- POST: Game Postponed
- CANC: Game Cancelled
- SUSP: Game Suspended
- AWD: Game Awarded
- ABD: Game Abandoned
*Games are updated every 15 seconds.*
*This endpoint requires at least one parameter.*
### Method
GET
### Endpoint
https://v1.basketball.api-sports.io/games
### Parameters
#### Query Parameters
- **timezone** (string) - Optional - The timezone for the games (e.g., 'Europe/London').
- **league** (integer) - Optional - The ID of the league.
- **season** (string) - Optional - The season of the league (e.g., '2019-2020').
- **team** (integer) - Optional - The ID of the team.
- **date** (string) - Optional - The date of the games (YYYY-MM-DD).
- **last** (integer) - Optional - The number of past games to retrieve.
- **next** (integer) - Optional - The number of upcoming games to retrieve.
- **id** (integer) - Optional - The ID of a specific game.
#### Header Parameters
- **x-apisports-key** (string) - Required - Your API-SPORTS Key.
### Request Example
```
GET https://v1.basketball.api-sports.io/games?timezone=Europe/London&league=12
Headers:
x-apisports-key: YOUR_API_KEY
```
### Response
#### Success Response (200)
- **response** (array) - A list of game objects.
- **game** (object) - Details of a game.
- **id** (integer) - The unique identifier for the game.
- **league** (object) - League information.
- **teams** (object) - Team information (home and away).
- **scores** (object) - Game scores.
- **time** (string) - Game time.
- **status** (string) - Game status.
#### Response Example
```json
{
"get": "games",
"parameters": {
"timezone": "Europe/London",
"league": "12"
},
"errors": [],
"results": 1,
"response": [
{
"id": 12345,
"league": {
"id": 12,
"name": "NBA",
"type": "League",
"season": "2019-2020",
"logo": null
},
"teams": {
"home": {"id": 137, "name": "Cleveland Cavaliers", "logo": null},
"away": {"id": 138, "name": "Los Angeles Lakers", "logo": null}
},
"scores": {
"home": {"total": 105},
"away": {"total": 110}
},
"time": "2023-10-27T19:00:00+00:00",
"status": "FT"
}
]
}
```
```
--------------------------------
### GET /players
Source: https://api-sports.io/documentation/basketball/v1/index
Retrieves data about players, optionally filtered by team, season, or player name. Requires your API-SPORTS key.
```APIDOC
## GET /players
### Description
Retrieves data about players, optionally filtered by team, season, or player name. Requires your API-SPORTS key.
### Method
GET
### Endpoint
https://v1.basketball.api-sports.io/players
### Parameters
#### Query Parameters
- **id** (integer) - Optional - The id of the player.
- **team** (integer) - Optional - The id of the team.
- **season** (string) - Optional - A valid season (e.g., "2023-2024").
- **search** (string) - Optional - The name of the player (minimum 3 characters).
#### Header Parameters
- **x-apisports-key** (string) - Required - Your API-SPORTS Key.
### Request Example
```php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://v1.basketball.api-sports.io/players');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString(array(
'team' => '1'
)));
$request->setHeaders(array(
'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
```
### Response
#### Success Response (200)
- **get** (string) - "players"
- **parameters** (object) - The query parameters used for the request.
- **errors** (array) - An array of errors, if any.
- **results** (integer) - The number of results returned.
- **response** (array) - An array of player objects, each containing player details.
#### Response Example
```json
{
"get": "players",
"parameters": {
"team": "1"
},
"errors": [],
"results": 1,
"response": [
{
"id": 139,
"name": "Denver Nuggets",
"nationnal": false,
"logo": null,
"country": {
"id": 5,
"name": "USA",
"code": "US",
"flag": "https://media.api-football.com/flags/us.svg"
}
}
]
}
```
```
--------------------------------
### HTML Widget Initialization
Source: https://api-sports.io/documentation/basketball/v1/index
This HTML demonstrates how to use the api-sports-widget. It shows a basic widget initialization and another widget configured with a custom theme and sport type.
```html