Skip to content

Getting Data in Batches

This following information only applies to the /teams, /events, and /odds endpoints.

Most endpoints will always return all results which match your query. However, since the /teams, /events, and /odds endpoints can potentially return hundreds or even thousands of results, the resulting objects are paginated/limited and must be fetched in batches.

The number of items by each request to these endpoints is determined by the limit parameter. This parameter currently has a default value of 10 but can be overridden up to a max value of 100.

In some cases you may want to fetch all of the results from these endpoints. To do this, you can feed the nextCursor in the resonse as the cursor parameter in your next request to pick up where you left off. When the response does not contain a nextCursor property, you have reached the end of the results.

Let’s take the following example, where we want to grab all finalized NBA events:

js
let nextCursor = null;
let eventData = [];
do {
  try {
    const response = await axios.get('/v1/events', {
      params: {
        leagueID: 'NBA',
        startsAfter: '2024-04-01',
        startsBefore: '2024-04-08',
        limit: 50,
        marketOddsAvailable: true,
        cursor: nextCursor
      }
    });

    // response.data will contain the 30 events for this request
    const data = response.data;

    eventData = eventData.concat(data.events);

    nextCursor = data?.nextCursor;

  } catch (error) {
    console.error('Error fetching events:', error);
    break;
  }
} while (nextCursor);

// Once you have this data, you could feed it to your betting model, display it in your sportsbook application, etc.
events.forEach((event) => {
  const odds = event.odds;
  Object.values(odds).forEach((oddObject) => {
    console.log(`Odd ID: ${oddObject.oddID}`);
    console.log(`Odd Value: ${oddObject.closeOdds}`);
  });
});
python
import requests

next_cursor = None
event_data = []

while True:
    try:
        response = requests.get('https://api.sportsgameodds.com/v1/events', params={
            'leagueID': 'NBA',
            'marketOddsAvailable': True,
            'limit': 50,
            'cursor': next_cursor
        })

        data = response.json()
        event_data.extend(data['events'])

        next_cursor = data.get('nextCursor')
        if not next_cursor:
            break

    except Exception as error:
        print(f'Error fetching events: {error}')
        break

for event in event_data:
    odds = event['odds']
    for odd_id, odd_object in odds.items():
        print(f'Odd ID: {odd_id}')
        print(f'Odd Value: {odd_object["closeOdds"]}')
ruby
require 'net/http'
require 'json'

next_cursor = nil
event_data = []

loop do
  uri = URI('https://api.sportsgameodds.com/v1/events')
  params = {
    leagueID: 'NBA',
    marketOddsAvailable: true,
    limit: 50,
    cursor: next_cursor
  }
  uri.query = URI.encode_www_form(params)

  response = Net::HTTP.get(uri)
  data = JSON.parse(response)

  event_data.concat(data['events'])

  next_cursor = data['nextCursor']
  break unless next_cursor

rescue StandardError => e
  puts "Error fetching events: #{e.message}"
  break
end

event_data.each do |event|
  odds = event['odds']
  odds.each do |odd_id, odd_object|
    puts "Odd ID: #{odd_id}"
    puts "Odd Value: #{odd_object['closeOdds']}"
  end
end
php
$next_cursor = null;
$event_data = [];

do {
    $ch = curl_init();
    $url = "https://api.sportsgameodds.com/v1/events?leagueID=NBA&marketOddsAvailable=true&limit=50&cursor=" . urlencode($next_cursor);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);

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

    $data = json_decode($response, true);
    $event_data = array_merge($event_data, $data['events']);

    $next_cursor = $data['nextCursor'];

} while ($next_cursor);

foreach ($event_data as $event) {
    $odds = $event['odds'];
    foreach ($odds as $odd_id => $odd_object) {
        echo "Odd ID: " . $odd_id . "\n";
        echo "Odd Value: " . $odd_object['closeOdds'] . "\n";
    }
}
java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONObject;

public class Main {
    public static void main(String[] args) {
        String nextCursor = null;
        List<JSONObject> eventData = new ArrayList<>();

        try {
            do {
                String apiUrl = "https://api.sportsgameodds.com/v1/events?leagueID=NBA&marketOddsAvailable=true&limit=50&cursor=" + URLEncoder.encode(nextCursor, "UTF-8");
                URL url = new URL(apiUrl);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");

                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());
                JSONArray events = data.getJSONArray("events");
                for (int i = 0; i < events.length(); i++) {
                    eventData.add(events.getJSONObject(i));
                }

                nextCursor = data.optString("nextCursor", null);

            } while (nextCursor != null);

            for (JSONObject event : eventData) {
                JSONObject odds = event.getJSONObject("odds");
                for (String key : odds.keySet()) {
                    JSONObject oddObject = odds.getJSONObject(key);
                    System.out.println("Odd ID: " + oddObject.getString("oddID"));
                    System.out.println("Odd Value: " + oddObject.getDouble("closeOdds"));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}