> ## Documentation Index
> Fetch the complete documentation index at: https://docs.novig.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GraphQL to REST Migration: Events API

> Migrate from GraphQL event queries to the new REST endpoints

## Overview

This guide is for API users migrating from GraphQL to REST. If you're new to the Novig API, start with the [Authentication guide](/api-reference/authentication).

## Authentication

All REST endpoints require authentication via Bearer token. Include your access token in every request:

```bash theme={null}
Authorization: Bearer YOUR_ACCESS_TOKEN
```

<Note>
  See the [Authentication guide](/api-reference/authentication) for instructions on obtaining an access token using your client credentials.
</Note>

## Environments

| Environment | Base URL               |
| ----------- | ---------------------- |
| Production  | `https://api.novig.us` |
| QA          | `https://api.novig.us` |

***

## Migration Reference

### 1. GetLeaguesQuery → `GET /nbx/v2/emm/event-metadata/leagues`

**Before (GraphQL):**

```graphql theme={null}
query GetLeaguesQuery {
  game(distinct_on: [league, sport]) {
    id
    league
    sport
  }
}
```

**After (REST):**

```bash theme={null}
curl --request GET \
  --url https://api.novig.us/nbx/v2/emm/event-metadata/leagues \
  --header "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

**Response:**

```json theme={null}
["NFL", "NBA", "MLB", "NHL", "NCAAF", "NCAAB", "MLS", "EPL", "UFC", "PGA"]
```

<Tip>
  Additional metadata endpoints are also available:

  * `GET /nbx/v2/emm/event-metadata/types` - All event types
  * `GET /nbx/v2/emm/event-metadata/statuses` - All event statuses
</Tip>

***

### 2. EventsByLeague → `GET /nbx/v2/emm/events`

**Before (GraphQL):**

```graphql theme={null}
query EventsByLeague($league: String!) {
  event(
    where: {
      _and: [
        {
          _or: [
            {
              _and: [
                { status: { _in: ["CLOSED_PREGAME", "OPEN_PREGAME"] } }
                { is_visible_pregame: { _eq: true } }
              ]
            }
            {
              _and: [
                { status: { _in: ["OPEN_INGAME", "DELAYED"] } }
                { is_visible_live: { _eq: true } }
              ]
            }
          ]
        }
        { league: { _eq: $league } }
        { type: { _eq: "Game" } }
      ]
    }
  ) {
    id
    type
    description
    status
    league
    scheduled_start
    game {
      id
      status
      scheduled_start
      homeTeam { id name symbol }
      awayTeam { id name symbol }
    }
  }
}
```

**After (REST):**

```bash theme={null}
curl --request GET \
  --url "https://api.novig.us/nbx/v2/emm/events?league=NFL&type=Game&status=OPEN_PREGAME&limit=100" \
  --header "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

**Query Parameters:**

| Parameter | Type   | Required | Description                                            |
| --------- | ------ | -------- | ------------------------------------------------------ |
| `league`  | string | No       | Filter by league (e.g., `NFL`, `NBA`, `MLB`)           |
| `type`    | string | No       | Filter by event type (e.g., `Game`)                    |
| `status`  | string | No       | Filter by status (e.g., `OPEN_PREGAME`, `OPEN_INGAME`) |
| `limit`   | number | No       | Number of results to return (max 100, default 100)     |
| `offset`  | number | No       | Pagination offset (default 0)                          |

**Response:**

```json theme={null}
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "type": "Game",
    "status": "OPEN_PREGAME",
    "description": "Kansas City Chiefs @ Buffalo Bills",
    "league": "NFL",
    "scheduledStart": "2025-01-26T18:30:00.000Z",
    "game": {
      "id": "game-uuid",
      "status": "SCHEDULED",
      "scheduledStart": "2025-01-26T18:30:00.000Z",
      "homeTeam": { "id": "team-uuid", "name": "Buffalo Bills", "symbol": "BUF" },
      "awayTeam": { "id": "team-uuid", "name": "Kansas City Chiefs", "symbol": "KC" }
    },
    "marketIds": ["market-uuid-1", "market-uuid-2", "market-uuid-3"]
  }
]
```

<Note>
  The REST endpoint returns a `marketIds` array for each event, which can reduce follow-up queries.

  **Visibility filtering:** Unlike the GraphQL query, the REST endpoint does not automatically filter by `is_visible_pregame` or `is_visible_live`. Filter by `status` to get the events you need.
</Note>

***

### 3. MarketsByEvent → `GET /nbx/v2/emm/events/getMarketsByEvent/:eventId`

**Before (GraphQL):**

```graphql theme={null}
query MarketsByEvent($eventId: uuid!) {
  event(where: { id: { _eq: $eventId } }) {
    markets(
      where: {
        _and: [
          { status: { _eq: "OPEN" } }
          {
            _or: [
              { is_consensus: { _eq: true } }
              { outcomes: { available: { _is_null: false } } }
            ]
          }
        ]
      }
    ) {
      id
      type
      description
      status
      player { name position }
      outcomes {
        id
        description
        available
        last
        type
        competitor { name }
        orders(
          where: {
            _and: [
              { status: { _eq: "OPEN" } }
              { currency: { _eq: "CASH" } }
            ]
          }
        ) {
          id
          outcome_id
          isBid
          qty
          price
          status
          currency
        }
      }
    }
  }
}
```

**After (REST):**

```bash theme={null}
curl --request GET \
  --url "https://api.novig.us/nbx/v2/emm/events/getMarketsByEvent/550e8400-e29b-41d4-a716-446655440000?currency=CASH" \
  --header "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

**Path Parameters:**

| Parameter | Type | Required | Description                       |
| --------- | ---- | -------- | --------------------------------- |
| `eventId` | uuid | Yes      | The event ID to fetch markets for |

**Query Parameters:**

| Parameter  | Type   | Required | Description                                    |
| ---------- | ------ | -------- | ---------------------------------------------- |
| `currency` | string | Yes      | Currency for orderbook data (`CASH` or `COIN`) |

**Response:**

```json theme={null}
[
  {
    "id": "market-uuid",
    "type": "Spread",
    "description": "Chiefs -3.5",
    "status": "OPEN",
    "eventId": "550e8400-e29b-41d4-a716-446655440000",
    "book": {
      "bids": [
        { "price": 0.52, "qty": 100 },
        { "price": 0.51, "qty": 250 }
      ],
      "asks": [
        { "price": 0.54, "qty": 150 },
        { "price": 0.55, "qty": 200 }
      ]
    }
  }
]
```

<Tip>
  The REST endpoint returns markets **with their current orderbook data included** in a single response, eliminating the need to fetch orders separately.
</Tip>

***

## Fetching a Single Event

A new endpoint is available to fetch a single event by ID:

```bash theme={null}
curl --request GET \
  --url "https://api.novig.us/nbx/v2/emm/events/550e8400-e29b-41d4-a716-446655440000" \
  --header "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

**Response:**

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "Game",
  "status": "OPEN_PREGAME",
  "description": "Kansas City Chiefs @ Buffalo Bills",
  "league": "NFL",
  "scheduledStart": "2025-01-26T18:30:00.000Z",
  "game": {
    "id": "game-uuid",
    "status": "SCHEDULED",
    "scheduledStart": "2025-01-26T18:30:00.000Z",
    "homeTeam": { "id": "team-uuid", "name": "Buffalo Bills", "symbol": "BUF" },
    "awayTeam": { "id": "team-uuid", "name": "Kansas City Chiefs", "symbol": "KC" }
  },
  "marketIds": ["market-uuid-1", "market-uuid-2", "market-uuid-3"]
}
```

***

## Need Help?

If you have questions or need assistance with the migration, please reach out to [developers@novig.co](mailto:developers@novig.co).
