# API Cheat Sheet - Quick Reference
URL: https://sportsgameodds.com/docs/basics/cheat-sheet

API Cheat Sheet - Quick Reference [#api-cheat-sheet---quick-reference]

<Callout type="info" title="TLDR">
  * Get an API key [here](/pricing). The key will be sent to your email.
  * Place your API key in the `apiKey` query param or the `x-api-key` header.
  * A full list of request endpoints and their parameters can be found [here](/docs/reference/).
  * Responses are in JSON format. The `data` field contains the data you queried for.
  * Use our [Data Explorer](/docs/explorer/) see the schema of the data that is returned.
  * The most commonly used endpoint is the `/events` endpoint. This returns a list of events with odds data. Common params include:
    * `oddsAvailable=true` - only return live/upcoming events with odds
    * `leagueID=NBA,NFL,MLB` - only return events for specified leagues
    * `oddID=points-home-game-ml-home,points-home-game-sp-home` - only return specified odds markets
    * `includeAltLines=true` - include alternate spread/over-under lines
</Callout>

Endpoints [#endpoints]

A full reference of all endpoints and their parameters can be found [here](/docs/reference/).

The API is currently on version 2 so each endpoint is prefixed with `https://api.sportsgameodds.com/v2`. For example the `/leagues` endpoint should be accessed at `https://api.sportsgameodds.com/v2/leagues`.

The main endpoint you'll use to fetch odds and scores/stats is the [`/events`](/docs/reference/#tag/events/GET/events/) endpoint.

Authentication [#authentication]

All requests require an [API key](/pricing)

Place it in the header as `x-api-key`.

```javascript
fetch("https://api.sportsgameodds.com/v2/events", {
  headers: { "x-api-key": "your-api-key-here" },
});
```

Or, place it in the query params as `apiKey`.

```javascript
fetch("https://api.sportsgameodds.com/v2/events?apiKey=YOUR_API_KEY_GOES_HERE");
```

Response Format [#response-format]

All responses follow a consistent JSON structure:

```json
{
  "success": true,
  "data": [...],
  "error": "...",
  "nextCursor": "...",
}
```

The `success` field tells you if the request was successful and returned data or not.
The `data` field contains a list of objects you queried for. The format of each object is dependent on the endpoint you called.
The `error` field contains an error message. It's only present if `success` is false.
The `nextCursor` field contains a cursor used to get the next page of data in some cases. More info [here](/docs/guides/data-batches).

Example Request [#example-request]

`https://api.sportsgameodds.com/v2/events?leagueID=NBA,NFL,MLB&oddsAvailable=true&limit=1&apiKey=YOUR_API_KEY`

To test this, simply replace `YOUR_API_KEY` with your actual API key and visit this URL in your browser.

You shoud see the next upcoming or live game for either NBA, NFL, or MLB along with all the odds data for that game.

* `leagueID=NBA,NFL,MLB` - Tells the API to only return data for NBA, NFL, and MLB games
* `oddsAvailable=true` - Tells the API to only return data for games where there are available/active odds markets
* `limit=1` - Tells the API to only return 1 game. By default the API sorts results by start time in ascending order.
* `apiKey=YOUR_API_KEY` - Authenticates your request.

Data Schema [#data-schema]

The best way to get a sense of how our data is structured is to play around with our [Data Explorer](/docs/explorer/).

In general, the data is organized into the following hierarchy:

1. Sports - fairly self-explanatory.
2. Leagues - each sport has one or more leagues.
3. Teams - each league has one or more teams.
4. Events - each team has one or more events.

The core unit that you'll likely be working with is the Event. Each Event represents a single game/match/fight/etc. The Event object also contains all odds markets for that event. An odds market represents both the type of bet and the side of the bet. Each has its own unique ID called an `oddID`. You can find data for a specific odds market on an Event object at the path: `Event.odds.<oddID>`. If you're looking for bookmaker specific data, you can find it here `Event.odds.<oddID>.byBookmaker.<bookmakerID>`.

Each oddID is a combination of other identifiers which uniquely identify the odds market. These identifiers are:

* `statID` - the statistic being measured (ex: "points", "assists", "rebounds", etc.)
* `statEntityID` - Who's performance on the stat is being measured (ex: "home", "away", "LEBRON\_JAMES", "all" (both teams), etc.)
* `periodID` - the period being tracked (ex: full game ("game"), first half ("1h"), etc.)
* `betTypeID` - the type of bet (ex: spread ("sp"), moneyline ("ml"), over/under ("ou"), etc.)
* `sideID` - the side of the bet (ex: "home", "away", "over", "under", "yes", "no", etc.)

By combining these identifiers, we can uniquely identify any odds market! Pretty cool, right?