Betfair API call 400 error response using fetch, where am I going wrong?

246 views Asked by At

I feel like this should be a simple thing to accomplish with node.js but the response keeps coming back as a 400 error, here is my code below, not much to debug. I'm starting to wonder whether the API documentation is faulty.

const fetch = require("node-fetch");

const apiKey = 'APP-KEY';
const sessionId = 'SESSION-KEY'
const url = "https://api.betfair.com/exchange/betting/json-rpc/v1"

async function listEventTypes()
{
    const body = '[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEventTypes", "params": {"filter":{}}, "id": 1}]';
    const response = await fetch(url, {
        method: 'POST',
        headers: {
            'X-Application' : apiKey,
            'X-Authentication' : sessionId,
            'Accept' : 'application/json',
            'Content-type' : 'application/json'
        },
        data: body          
    }).then(response => {
    if (response.ok) {
      return response.json();
    }
    throw new Error('Request failed!');
  }, networkError => {
    console.log(networkError.message)
  })
}


function runTheApp()
{   
    console.log('Starting the Betfair Horse Racing API App!\n');
    console.log(listEventTypes());
}

runTheApp();
0

There are 0 answers