Repository navigation
Expand file tree
/
Copy pathsample-v3.js
More file actions
60 lines (47 loc) · 1.63 KB
/
Copy pathsample-v3.js
File metadata and controls
60 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const axios = require('axios')
// An api key is emailed to you when you sign up to a plan
// Get a free API key at https://api.the-odds-api.com/
const api_key = process.argv[2] || 'YOUR_API_KEY'
const sport_key = 'upcoming' // use the sport_key from the /sports endpoint below, or use 'upcoming' to see the next 8 games across all sports
const region = 'uk' // uk | us | eu | au
const market = 'h2h' // h2h | spreads | totals
/*
First get a list of in-season sports
the sport 'key' from the response can be used to get odds in the next request
*/
axios.get('https://api.the-odds-api.com/v3/sports', {
params: {
api_key: api_key
}
})
.then(response => {
console.log(response.data.data)
})
.catch(error => {
console.log('Error status', error.response.status)
console.log(error.response.data)
})
/*
Now get a list of live & upcoming games for the sport you want, along with odds for different bookmakers
*/
axios.get('https://api.the-odds-api.com/v3/odds', {
params: {
api_key: api_key,
sport: sport_key,
region: region,
mkt: market,
}
})
.then(response => {
// response.data.data contains a list of live and
// upcoming events and odds for different bookmakers.
// Events are ordered by start time (live events are first)
console.log(JSON.stringify(response.data.data))
// Check your usage
console.log('Remaining requests',response.headers['x-requests-remaining'])
console.log('Used requests',response.headers['x-requests-used'])
})
.catch(error => {
console.log('Error status', error.response.status)
console.log(error.response.data)
})