draftkings apiDashboard ↗

INDEPENDENT DEVELOPER REFERENCE

Can I call the API from browser JavaScript?

Do not call it from browser code. A key in a client bundle is readable by anyone, and all keys on an account share one allowance. Data endpoints also do not send cross-origin headers. Call the API from a server route and return only what your page needs.

Editorial review: · Not a live coverage report

A small server route

Your route holds the key in its environment, validates what the browser asked for, and caches the response. Caching protects your allowance as well as your response time, since API responses are themselves no-store.

Keep the key out of the bundle
// app/api/board/route.ts, in your own Next.js app
export async function GET() {
  const r = await fetch(
    "https://draftkingsapi.com/api/v1/pick6/projections?sport=NHL&limit=25",
    { headers: { Authorization: "Bearer " + process.env.DRAFTKINGS_API_KEY } },
  );
  if (!r.ok) return Response.json({ error: "Upstream " + r.status }, { status: 502 });
  const { data } = await r.json();
  return Response.json(data.filter((row) => !row.stale));
}

Check the recorded data

Related resources

Independent service operated by DD Inc., not affiliated with or endorsed by DraftKings. Technical access is not a redistribution license. No wagering: this service does not place, recommend or settle entries or bets. Check sources and status for actual capture context.