Permintaan pertama Anda ke API OddFeeds

Dari kunci API hingga odds satu pertandingan dalam empat permintaan, masing-masing mengambil id dari respons sebelumnya.

6 menit baca ·

Setiap respons API memberikan id untuk permintaan berikutnya: negara mengarah ke liga, liga ke pertandingan, dan pertandingan ke odds-nya. Panduan ini menjalankan keempat permintaan tersebut secara berurutan dan menampilkan isi dari setiap respons.

Kunci API Anda

Setiap permintaan berupa POST ke satu alamat, dengan kunci Anda di header: Authorization: Bearer diikuti oleh kunci tersebut. Kunci Anda ada di halaman akun setelah Anda memilikinya, dan halaman layanan menjelaskan cara mendapatkannya.

1. Negara

Permintaan tanpa scope akan menampilkan daftar negara yang memiliki odds saat ini, baik sebelum kick-off maupun in-play.

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"prematch":true,"inplay":true}'

Respons · Respons dari API pada 26 Nov 2026, menampilkan baris-baris pertama. Respons Anda memiliki ID lain: gunakan ID tersebut untuk permintaan berikutnya.

Respons dalam JSON: 1. Negara
{
  "status": "ok",
  "data": [
    {
      "id": 136,
      "name": "Slovakia",
      "prematch_leagues_cnt": 1,
      "inplay_leagues_cnt": 0
    },
    {
      "id": 42,
      "name": "Costa Rica",
      "prematch_leagues_cnt": 2,
      "inplay_leagues_cnt": 0
    }
  ],
  "time": "2026-11-26T15:14:19",
  "ms": "479us"
}

prematch_leagues_cnt dan inplay_leagues_cnt menghitung jumlah liga suatu negara yang memiliki odds sebelum kick-off dan in-play. Pilih negara dengan jumlah di atas nol.

2. Liga di suatu negara

Masukkan id negara ke dalam tournament_ids. Respons akan menampilkan daftar liga beserta jumlah pertandingan yang memiliki odds.

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"scope":"leagues","tournament_ids":[136]}'

Respons · Respons dari API pada 26 Nov 2026. Respons Anda memiliki ID lain: gunakan ID tersebut untuk permintaan berikutnya.

Respons dalam JSON: 2. Liga di suatu negara
{
  "status": "ok",
  "data": [
    {
      "id": 10618,
      "tournament_id": 136,
      "name": "Super Liga",
      "prematch_matches_cnt": 6,
      "inplay_matches_cnt": 0
    }
  ],
  "time": "2026-11-26T15:14:19",
  "ms": "400us"
}

3. Pertandingan di suatu liga

Masukkan id liga ke dalam league_ids.

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"scope":"matches","league_ids":[10618]}'

Respons · Respons dari API pada 26 Nov 2026, menampilkan baris-baris pertama. Respons Anda memiliki ID lain: gunakan ID tersebut untuk permintaan berikutnya.

Respons dalam JSON: 3. Pertandingan di suatu liga
{
  "status": "ok",
  "data": [
    {
      "id": 13682297,
      "league_id": 10618,
      "teams": {
        "home": "Dukla Banska Bystrica",
        "away": "MFK Ruzomberok"
      },
      "start": "2026-11-28T14:30:00",
      "active": {
        "prematch": 1,
        "inplay": 0
      },
      "stats": {
        "start": "2026-11-28T14:30:00"
      }
    },
    {
      "id": 13683299,
      "league_id": 10618,
      "teams": {
        "home": "Slovan Bratislava",
        "away": "FC Kosice"
      },
      "start": "2026-11-28T17:00:00",
      "active": {
        "prematch": 1,
        "inplay": 0
      },
      "stats": {
        "start": "2026-11-28T17:00:00"
      }
    }
  ],
  "time": "2026-11-26T15:14:20",
  "ms": "700us"
}

start adalah waktu kick-off dalam UTC. active menunjukkan mode mana yang memiliki odds saat ini, dan pertandingan in-play juga memuat stats.runtime berisi menit dan skor.

4. Odds untuk satu pertandingan

Masukkan id pertandingan ke dalam match_ids. Tanpa bookmaker_ids, respons akan memuat setiap bookmaker yang didukung oleh kunci Anda.

curl -X POST https://oddfeeds.com/api/v1/feeds \
  -H "Authorization: Bearer ofk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"scope":"odds","match_ids":[13682297]}'

Respons · Respons dari API pada 26 Nov 2026, menampilkan baris-baris pertama.

Respons dalam JSON: 4. Odds untuk satu pertandingan
{
  "status": "ok",
  "data": {
    "prematch": [
      {
        "id": 390798263,
        "active": 1,
        "match_id": 13682297,
        "event_id": 72533074,
        "bookmaker": {
          "id": 59,
          "name": "Bet8"
        },
        "datetime": "2026-11-26T01:35:42",
        "period_id": 0,
        "type_id": 11,
        "order": 1,
        "back_lay_id": 0,
        "liquidity": -1,
        "hc": 0,
        "hc_as_draw": 0,
        "price": 1.231,
        "nav": "{\"v\":1,\"scope\":\"prematch\",\"eventId\":\"18450709\",\"oddId\":\"4..."
      },
      {
        "id": 390634623,
        "active": 1,
        "match_id": 13682297,
        "event_id": 72531615,
        "bookmaker": {
          "id": 34,
          "name": "Trbet"
        },
        "datetime": "2026-11-26T01:36:24",
        "period_id": 0,
        "type_id": 9,
        "order": 1,
        "back_lay_id": 0,
        "liquidity": -1,
        "hc": 2,
        "hc_as_draw": 0,
        "price": 1.14,
        "nav": "{\"v\":1,\"scope\":\"prematch\",\"eventId\":\"42575268\",\"oddId\":\"7..."
      }
    ],
    "inplay": []
  },
  "time": "2026-11-26T15:15:19",
  "ms": "15.97ms"
}

Baris data hadir dalam dua daftar, prematch dan inplay, masing-masing untuk satu mode, dan tiap baris adalah satu harga dari satu bookmaker. Berikut adalah bidang yang Anda baca terlebih dahulu:

Bidang dari baris odds
BidangArti
bookmakerid + name of the source bookmaker.
type_idMarket type, see the type_id table.
period_id0 = first half, 1 = full time, 6 = second half.
hcThe handicap / total line, e.g. -0.5 or 2.5. On 1X2 rows (type_id 2, 3, 4) a non-zero hc is a European handicap line, and for correct score (type_id 66) it carries the score; see the type_id table.
priceThe odd, decimal format. On an exchange it's the price as the exchange shows it, with no commission taken off.
datetimeWhen this price last changed (UTC).

Arti dari setiap angka dalam baris dapat dilihat di tabel referensi dokumentasi.

Saat API menolak permintaan

Berikut dua respons yang paling sering ditemui pada permintaan pertama, sesuai pesan dari API:

Respons error
Status HTTPArti
400A body that is not valid JSON, a malformed parameter, a scope without its id list, or id lists that count as more requests than one request may (see 429); the error field says what was wrong.
401Missing or unknown API key.

Seluruh alur dalam satu skrip

Skrip ini melakukan empat permintaan secara berurutan dan meneruskan setiap id. Skrip membaca kunci Anda dari variabel lingkungan ODDFEEDS_KEY, sehingga kunci tetap aman di luar kode Anda.

// The whole walk: the countries, a country's leagues, a league's
// matches and the odds of one match. Run it with your key:
//   ODDFEEDS_KEY=<your key> node first-request.mjs
const API = process.env.ODDFEEDS_URL || 'https://oddfeeds.com/api/v1/feeds';

async function ask(body) {
  const res = await fetch(API, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.ODDFEEDS_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body),
  });
  const feed = await res.json();
  if (feed.status !== 'ok') throw new Error(`${res.status}: ${feed.error}`);
  return feed.data;
}

const countries = await ask({ prematch: true, inplay: true });
const country = countries.find(
  (c) => c.prematch_leagues_cnt > 0 || c.inplay_leagues_cnt > 0);
if (!country) throw new Error('No country has odds right now.');

const leagues = await ask({ scope: 'leagues', tournament_ids: [country.id] });
const league = leagues.find(
  (l) => l.prematch_matches_cnt > 0 || l.inplay_matches_cnt > 0);

const matches = await ask({ scope: 'matches', league_ids: [league.id] });
const match = matches[0];

const odds = await ask({ scope: 'odds', match_ids: [match.id] });
const rows = [...odds.prematch, ...odds.inplay];

const { home, away } = match.teams;
console.log(`${country.name} / ${league.name} / ${home} - ${away}: ${rows.length} prices`);
for (const r of rows.slice(0, 5)) {
  console.log(r.bookmaker.name, r.type_id, r.hc, r.price);
}

Selanjutnya

Dokumentasi memuat semua tabel scope, bidang, dan pasar, sementara halaman contoh penggunaan menampilkan apa yang dibangun pengembang dengan permintaan ini.

Coba dengan data live

Playground di akun gratis menjalankan permintaan ini di browser Anda menggunakan data live.