### 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
``` -------------------------------- ### Fetch Basketball Leagues via Shell (wget) Source: https://api-sports.io/documentation/basketball/v1/index Retrieves basketball league information using the `wget` command-line utility. This example disables certificate checking and includes the necessary API key header. ```Shell wget --no-check-certificate --quiet \ --method GET \ --timeout=0 \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' \ 'https://v1.basketball.api-sports.io/leagues' ``` -------------------------------- ### Fetch Basketball Leagues using Go and net/http Source: https://api-sports.io/documentation/basketball/v1/index This Go program demonstrates fetching basketball league data using the native 'net/http' package. It constructs an HTTP GET request, adds the 'x-apisports-key' header, sends the request, and reads the response body. Error handling is included for request creation and execution. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://v1.basketball.api-sports.io/leagues" method := "GET" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Targeting Widgets via Modal (HTML) Source: https://api-sports.io/documentation/basketball/v1/index Illustrates how to configure widgets to open their content within a modal window using the 'data-target-*' attribute set to 'modal'. This provides a non-intrusive way to display detailed information without leaving the current page. ```html ``` -------------------------------- ### Get API Status Source: https://api-sports.io/documentation/basketball/v1/index Retrieves the current API status, including account details, subscription plan, and request limits. This call does not count against the daily quota. It is a GET request to the 'status' endpoint. ```javascript get("https://v1.basketball.api-sports.io/status"); // response { "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 Seasons List PHP Source: https://api-sports.io/documentation/basketball/v1/index This PHP code snippet demonstrates how to fetch the list of available seasons from the API-SPORTS API. It requires an API key and makes a GET request to the `/seasons` endpoint. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/seasons'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Basketball Leagues via Ruby (Net::HTTP) Source: https://api-sports.io/documentation/basketball/v1/index Fetches basketball league data using Ruby's standard `Net::HTTP` library. This example includes SSL verification settings and requires the 'x-apisports-key' header. ```Ruby require 'uri' require 'net/http' require 'openssl' url = URI("https://v1.basketball.api-sports.io/leagues") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-apisports-key"] = 'XxXxXxXxXxXxXxXxXxXxXxXx' response = http.request(request) puts response.read_body ``` -------------------------------- ### Get Timezone List PHP Source: https://api-sports.io/documentation/basketball/v1/index This PHP code snippet demonstrates how to fetch the list of available timezones from the API-SPORTS API. It requires an API key and makes a GET request to the `/timezone` endpoint. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/timezone'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Basketball Leagues via Shell (Httpie) Source: https://api-sports.io/documentation/basketball/v1/index Uses the Httpie command-line tool to fetch basketball league data. This method is concise and requires the 'x-apisports-key' header. ```Shell http --follow --timeout 3600 GET 'https://v1.basketball.api-sports.io/leagues' \ x-apisports-key:'XxXxXxXxXxXxXxXxXxXxXxXx' \ ``` -------------------------------- ### Get Basketball Bookmakers - PHP Source: https://api-sports.io/documentation/basketball/v1/index This snippet demonstrates how to retrieve a list of all available basketball bookmakers using the PHP http client. It makes a GET request to the /bookmakers endpoint, requiring an API key in the headers. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/bookmakers'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Configuring Widget Language (HTML) Source: https://api-sports.io/documentation/basketball/v1/index Shows how to set the display language for widgets using the 'data-lang' attribute. It also demonstrates the use of 'data-custom-lang' to load a custom JSON translation file, allowing for overrides and translations of missing terms. The custom file takes precedence over the standard language setting if a key exists in both. ```html ``` ```html ``` -------------------------------- ### Get Basketball Bets - PHP Source: https://api-sports.io/documentation/basketball/v1/index This PHP code snippet shows how to fetch all available basketball bets using the http client. It sends a GET request to the /bets endpoint, necessitating an x-apisports-key in the request headers for authentication. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/bets'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Basketball Leagues via Swift (URLSession) Source: https://api-sports.io/documentation/basketball/v1/index Fetches basketball league data using Swift's `URLSession` framework. This example includes semaphore for handling asynchronous operations and requires the 'x-apisports-key' header. ```Swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url: URL(string: "https://v1.basketball.api-sports.io/leagues")!,timeoutInterval: Double.infinity) request.addValue("XxXxXxXxXxXxXxXxXxXxXxXx", forHTTPHeaderField: "x-apisports-key") request.httpMethod = "GET" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ``` -------------------------------- ### Get Countries List PHP Source: https://api-sports.io/documentation/basketball/v1/index This PHP code snippet demonstrates how to fetch the list of available countries from the API-SPORTS API. It requires an API key and makes a GET request to the `/countries` endpoint. Query parameters can be used to filter results. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/countries'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Targeting Widgets by ID (HTML) Source: https://api-sports.io/documentation/basketball/v1/index Demonstrates how to use the 'data-target-*' attributes to specify an HTML element (by ID) for rendering a widget. This allows for precise placement of widget content on your webpage. It requires a parent widget to trigger the targeting and a target element with a corresponding ID. ```html
``` -------------------------------- ### Get Basketball Leagues Request Sample (PHP) Source: https://api-sports.io/documentation/basketball/v1/index This snippet demonstrates how to fetch a list of basketball leagues using the API-SPORTS v1 API with PHP. It requires an API key and specifies the endpoint URL. The response body, containing league data, is then printed. ```PHP $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.basketball.api-sports.io/leagues'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Basketball Leagues using Javascript Fetch API Source: https://api-sports.io/documentation/basketball/v1/index This Javascript code uses the built-in Fetch API to get basketball league data. It defines the request headers, including the 'x-apisports-key', configures the request options for a GET method, and then calls fetch. The response is processed to log the text content or any errors encountered. ```javascript var myHeaders = new Headers(); myHeaders.append("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx"); var requestOptions = { method: 'GET', headers: myHeaders, redirect: 'follow' }; fetch("https://v1.basketball.api-sports.io/leagues", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error)); ``` -------------------------------- ### Fetch Basketball Leagues with OCaml Cohttp Source: https://api-sports.io/documentation/basketball/v1/index Fetches basketball league data using the OCaml Cohttp library. Requires 'lwt' and 'cohttp-lwt-unix' packages. Sends a GET request to the leagues endpoint with an API key in the headers and prints the response body. ```ocaml open Lwt open Cohttp open Cohttp_lwt_unix let reqBody = let uri = Uri.of_string "https://v1.basketball.api-sports.io/leagues" in let headers = Header.init () |> fun h -> Header.add h "x-apisports-key" "XxXxXxXxXxXxXxXxXxXxXxXx" in Client.call ~headers `GET uri >>= fun (_resp, body) -> body |> Cohttp_lwt.Body.to_string >|= fun body -> body let () = let respBody = Lwt_main.run reqBody in print_endline (respBody) ``` -------------------------------- ### Fetch Basketball Leagues using C# and RestSharp Source: https://api-sports.io/documentation/basketball/v1/index This C# code uses the RestSharp library to make a GET request to the API Sports v1 leagues endpoint. It configures the client, creates a GET request, adds the 'x-apisports-key' header, and executes the request, printing the response content to the console. Ensure RestSharp is added as a NuGet package. ```csharp var client = new RestClient("https://v1.basketball.api-sports.io/leagues"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ``` -------------------------------- ### GET /seasons Source: https://api-sports.io/documentation/basketball/v1/index Retrieves a list of all available seasons. These seasons can be used as filters in other API endpoints. ```APIDOC ## GET /seasons ### Description Retrieves a list of all available seasons. These seasons can be used as filters in other API endpoints. ### Method GET ### Endpoint https://v1.basketball.api-sports.io/seasons ### Parameters #### 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/seasons'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` ### Response #### Success Response (200) - **get** (string) - Indicates the endpoint called. - **parameters** (array) - List of parameters used. - **errors** (array) - List of errors, if any. - **results** (integer) - The number of results returned. - **response** (array) - An array of season strings or integers. #### Response Example ```json { "get": "seasons", "parameters": [], "errors": [], "results": 8, "response": [ "2015-2016", "2016-2017", 2017, "2017-2018", 2018, "2018-2019", 2019, "2019-2020" ] } ``` ``` -------------------------------- ### Fetch Basketball Leagues with Node.js Requests Source: https://api-sports.io/documentation/basketball/v1/index Fetches basketball league data using the 'request' library in Node.js. Requires the 'request' package. Sends a GET request to the leagues endpoint with an API key in the headers and logs the response body or any errors. ```javascript var request = require('request'); var options = { 'method': 'GET', 'url': 'https://v1.basketball.api-sports.io/leagues', 'headers': { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx', } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); }); ```