# Teams Guide - Fetch by ID, League, or Sport
URL: https://sportsgameodds.com/docs/guides/fetching-teams

Teams Guide - Fetch by ID, League, or Sport [#teams-guide---fetch-by-id-league-or-sport]

Overview [#overview]

The Sports Game Odds API provides the ability to fetch a list of teams or a specific team's details.

You can use a `sportID` or `leagueID` to get a list of associated teams and their details. You can also pass a `teamID` to just get a single team's details. Note that when specifying a `teamID`, it will still return as an array, just with a single object in it.

Fetching by Team [#fetching-by-team]

Let's take the following example, where we want to fetch the details of a specific NBA team:

<Tabs items={['Javascript', 'Python', 'Ruby', 'PHP', 'Java']}>
  <Tab value="Javascript">
    ```js
    await axios.get("/v2/teams", {
      params: {
        teamID: "LOS_ANGELES_LAKERS_NBA",
      },
    });
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import requests

    response = requests.get(
        'https://api.sportsgameodds.com/v2/teams?teamID=LOS_ANGELES_LAKERS_NBA',
        headers={'X-Api-Key': 'YOUR_TOKEN'}
    )
    print(response.json())
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require 'net/http'
    require 'json'

    uri = URI('https://api.sportsgameodds.com/v2/teams?teamID=LOS_ANGELES_LAKERS_NBA')
    request = Net::HTTP::Get.new(uri)
    request['X-Api-Key'] = 'YOUR_TOKEN'

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request(request)
    end

    puts JSON.parse(response.body)
    ```
  </Tab>

  <Tab value="PHP">
    ```php
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api.sportsgameodds.com/v2/teams?teamID=LOS_ANGELES_LAKERS_NBA');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-Api-Key: YOUR_TOKEN'
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;
    ```
  </Tab>

  <Tab value="Java">
    ```java
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import org.json.JSONObject;

    public class Main {
        public static void main(String[] args) {
            try {
                URL url = new URL("https://api.sportsgameodds.com/v2/teams?teamID=LOS_ANGELES_LAKERS_NBA");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setRequestProperty("X-Api-Key", "YOUR_TOKEN");

                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String inputLine;
                StringBuffer content = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }

                in.close();
                conn.disconnect();

                JSONObject data = new JSONObject(content.toString());
                System.out.println(data.toString(2));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    ```
  </Tab>
</Tabs>

This will return a response that looks something like this:

```json
{
  "success": true,
  "data": [
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "LAL",
        "medium": "Lakers",
        "long": "Los Angeles Lakers"
      },
      "leagueID": "NBA",
      "teamID": "LOS_ANGELES_LAKERS_NBA"
    }
  ]
}
```

Fetching by league [#fetching-by-league]

If you wanted to fetch a list of all the teams in the NBA, your request would look something like this:

<Tabs items={['Javascript', 'Python', 'Ruby', 'PHP', 'Java']}>
  <Tab value="Javascript">
    ```js
    await axios.get("/v2/teams", {
      params: {
        leagueID: "NBA",
      },
    });
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import requests

    response = requests.get(
        'https://api.sportsgameodds.com/v2/teams?leagueID=NBA',
        headers={'X-Api-Key': 'YOUR_TOKEN'}
    )
    print(response.json())
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require 'net/http'
    require 'json'

    uri = URI('https://api.sportsgameodds.com/v2/teams?leagueID=NBA')
    request = Net::HTTP::Get.new(uri)
    request['X-Api-Key'] = 'YOUR_TOKEN'

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request(request)
    end

    puts JSON.parse(response.body)
    ```
  </Tab>

  <Tab value="PHP">
    ```php
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api.sportsgameodds.com/v2/teams?leagueID=NBA');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-Api-Key: YOUR_TOKEN'
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;
    ```
  </Tab>

  <Tab value="Java">
    ```java
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import org.json.JSONObject;

    public class Main {
        public static void main(String[] args) {
            try {
                URL url = new URL("https://api.sportsgameodds.com/v2/teams?leagueID=NBA");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setRequestProperty("X-Api-Key", "YOUR_TOKEN");

                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String inputLine;
                StringBuffer content = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }

                in.close();
                conn.disconnect();

                JSONObject data = new JSONObject(content.toString());
                System.out.println(data.toString(2));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    ```
  </Tab>
</Tabs>

This will return a response that looks something like this:

```json
{
  "nextCursor": "MILWAUKEE_BUCKS_NBA",
  "success": true,
  "data": [
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "LAL",
        "medium": "Lakers",
        "long": "Los Angeles Lakers"
      },
      "leagueID": "NBA",
      "teamID": "LAKERS_NBA",
      "colors": {
        "secondary": "#FFFFFF",
        "primaryContrast": "#000000",
        "secondaryContrast": "#552583",
        "primary": "#552583"
      }
    },
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "BOS",
        "medium": "Celtics",
        "long": "Boston Celtics"
      },
      "leagueID": "NBA",
      "teamID": "CELTICS_NBA",
      "colors": {
        "secondary": "#FFFFFF",
        "primaryContrast": "#000000",
        "secondaryContrast": "#007A33",
        "primary": "#007A33"
      }
    },
    // ...
    // Up to 30 objects may be returned in this object. If there are more available
    // then you'll see a nextCursor property you can use to fetch the next
    // page of related objects.
  ]
}
```

Fetching by sport [#fetching-by-sport]

If you wanted to fetch a list of all basketball teams across all of our supported leagues, your request would look something like this:

<Tabs items={['Javascript', 'Python', 'Ruby', 'PHP', 'Java']}>
  <Tab value="Javascript">
    ```js
    await axios.get("/v2/teams", {
      params: {
        sportID: "BASKETBALL",
      },
    });
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import requests

    response = requests.get(
        'https://api.sportsgameodds.com/v2/teams?sportID=BASKETBALL',
        headers={'X-Api-Key': 'YOUR_TOKEN'}
    )
    print(response.json())
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require 'net/http'
    require 'json'

    uri = URI('https://api.sportsgameodds.com/v2/teams?sportID=BASKETBALL')
    request = Net::HTTP::Get.new(uri)
    request['X-Api-Key'] = 'YOUR_TOKEN'

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request(request)
    end

    puts JSON.parse(response.body)
    ```
  </Tab>

  <Tab value="PHP">
    ```php
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'https://api.sportsgameodds.com/v2/teams?sportID=BASKETBALL');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-Api-Key: YOUR_TOKEN'
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;
    ```
  </Tab>

  <Tab value="Java">
    ```java
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import org.json.JSONObject;

    public class Main {
        public static void main(String[] args) {
            try {
                URL url = new URL("https://api.sportsgameodds.com/v2/teams?sportID=BASKETBALL");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setRequestProperty("X-Api-Key", "YOUR_TOKEN");

                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String inputLine;
                StringBuffer content = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }

                in.close();
                conn.disconnect();

                JSONObject data = new JSONObject(content.toString());
                System.out.println(data.toString(2));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    ```
  </Tab>
</Tabs>

This will return a response that looks something like this:

```json
{
  "nextCursor": "BELMONT_NCAAB",
  "success": true,
  "data": [
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "LAL",
        "medium": "Lakers",
        "long": "Los Angeles Lakers"
      },
      "leagueID": "NBA",
      "teamID": "LAKERS_NBA"
    },
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "BOS",
        "medium": "Celtics",
        "long": "Boston Celtics"
      },
      "leagueID": "NBA",
      "teamID": "CELTICS_NBA"
    },
    {
      "sportID": "BASKETBALL",
      "names": {
        "short": "GSW",
        "medium": "Warriors",
        "long": "Golden State Warriors"
      },
      "leagueID": "NBA",
      "teamID": "WARRIORS_NBA"
    },
    // ...
    // Up to 30 objects may be returned in this object. If there are more available
    // then you'll see a nextCursor property you can use to fetch the next
    // page of related objects.
  ]
}
```