├── .gitignore ├── package.json ├── DraftKingsApi.js └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "draft-kings-api-documentation", 3 | "version": "1.0.0", 4 | "description": "This is unofficial documentation for the Draft Kings API. Draft Kings very much does NOT intend to have this API used by the public, but then again they don't lock the API down either. If you've ever dealt with APIs that are only intended to be used by the company deploying them, you would know that this documentation is completely without warranty and could go out of date at any moment. Similarly, Draft Kings absolutely will not care at all if you build a big application based on their current API and then roll out a V2 the next day and deprecate V1. You have been warned. :-)", 5 | "main": "DraftKingsApi.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "got": "^11.8.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DraftKingsApi.js: -------------------------------------------------------------------------------- 1 | const got = require('got'); 2 | const util = require('util'); 3 | 4 | 5 | (async () => { 6 | try { 7 | //Get the contests 8 | const contestsResponse = await got('https://www.draftkings.com/lobby/getcontests?sport=LOL'); 9 | const contestsJson = JSON.parse(contestsResponse.body); 10 | 11 | //Loop through all contests and build a list of the unique draft groups 12 | let groupIdList = []; 13 | contestsJson['Contests'].forEach(contest => { 14 | if (!groupIdList.includes(contest['dg'])) { 15 | groupIdList.push(contest['dg']) 16 | } 17 | }); 18 | 19 | //For each draft group, grab the draftables by replacing the parameter in the URL with the correct group Id 20 | for (const groupId of groupIdList) { 21 | console.log('Players for GroupId:') 22 | console.log(groupId); 23 | console.log('\n') 24 | 25 | const draftablePlayersResponse = await got(util.format('https://api.draftkings.com/draftgroups/v1/draftgroups/%s/draftables', groupId)); 26 | const draftableplayersJson = JSON.parse(draftablePlayersResponse.body); 27 | 28 | //Nice! Now we have the players so let's just console.log them as a simple example 29 | draftableplayersJson['draftables'].forEach(player => { 30 | console.log(player['displayName']); 31 | console.log(player['position']); 32 | console.log(player['salary']); 33 | console.log('***') 34 | }); 35 | } 36 | 37 | } catch (error) { 38 | console.log(error); 39 | } 40 | })(); -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Unofficial Documentation for the Draft Kings API 2 | ## Description 3 | This is unofficial documentation for the Draft Kings API. Draft Kings very much does NOT intend to have this API used by the public, but then again they don't lock the API down either. If you've ever dealt with APIs that are only intended to be used by the company deploying them, you would know that this documentation is completely without warranty and could go out of date at any moment. Similarly, Draft Kings absolutely will not care at all if you build a big application based on their current API and then roll out a V2 the next day and deprecate V1. You have been warned. :-) 4 | 5 | ## Core Data Structure 6 | There's a lot of information in the API documentation that is probably superfluous, so I'll give a summary of what most people are probably reading this for: the slate for every draft group. But first, a quick note about the example URLs I'm about to use. Given how transient a lot of the data is (slates come and go quickly), many of the links are probably broken. Generally the part of the URL needing updating with fresh data is quite obvious, so they should still be helpful. 7 | 8 | Anyway, the core data structure is as follows: 9 | 10 | 1. **Sports:** Highest level entity which inturn consist of. You can get the sport in question by clicking the sport in the top nav bar. For instance, clicking LOL nets: https://www.draftkings.com/lobby#/LOL. This is useful because if you're looking to get a JSON list of contests for a particular sport you can feed in the sport as a parameter (https://www.draftkings.com/lobby/getcontests?sport=LOL). Alternatively, you could stick to using the API by hitting https://api.draftkings.com/sites/US-DK/sports/v1/sports?format=json to return a JSON list. 11 | 2. **Games:** Which are not the things you enter to win, they are basically rulesets. You can actually get the details of rulesets, or game types, from a DK API: https://api.draftkings.com/lineups/v1/gametypes/1/rules. Game rulesets are the basis for... 12 | 3. **Contests:** Which are the individual things you can pay money to enter in. As was mentioned earlier, you can get all contests or contests for a specific sport using https://www.draftkings.com/lobby/getcontests?sport=LOL. This will return a ton of data but it is quite cryptically formatted. It's easy enough to guess at the data points but if you want additional detail and fully labeled attributes, you could use this API by pulling the contest ID, for example: https://api.draftkings.com/contests/v1/contests/105313170?format=json 13 | 4. **Draft Groups:** Each Contest has a Draft Group, which is basically a unique ID for that particular slate. It is the most important building block of getting to the information you want. Draft Groups house information like the teams on the slate, contest start time and most importantly... 14 | 5. **Draftables:** This is probably what most of you are after. The players and salaries for a given Draft Group. You can get that paydirt by hitting this URL and of course replacing the ID at the end with whatever slate you're after: https://api.draftkings.com/draftgroups/v1/draftgroups/46589/draftables 15 | 16 | ## Example Retrieving Slates and Players 17 | Ok now to the actual slate you're no doubt impatiently waiting for. I'm going to use League of Legends for this example because I'm a nerd who enjoys doing data science stuff on esports. The high level code flow is: 18 | 19 | 1. If you wanted to grab every slate as it becomes available for a specific sport you would first need the Draft Groups for the sport. Draft Groups are basically the ID for each slate, so they're very important. Let's say you don't want to parse 100s of contests so you may want filter down to just a single sport. To do this you would call https://www.draftkings.com/lobby/getcontests?sport=LOL. 20 | 2. From that you would want to get a distinct set of all the Draft Groups. These IDs have the key of ['dg'] for "Draft Group" and they are found under ['Contests'] which is a list of all contests. Grab all the Draft Groups IDs, filter them to a distinct set (if there are two slates, there would be two Draft Groups), and with that list of IDs you're nearly there. 21 | 3. Now you can loop through all the slates on deck for that particular sport using these IDs. To do this, use the Draftables API to get players, salaries, etc. whcih is found here: https://api.draftkings.com/draftgroups/v1/draftgroups/46589/draftables 22 | 4. This page will have all the knowledge you would want to host a fantasy league, programatically run a lineup optimizer, etc. etc. 23 | 24 | Alright, how 'bout some code? I'll write this quick script with Node because for some reason I'm in the mood to use brackets everywhere and type "await" a lot. 25 | 26 | ```javascript 27 | const got = require('got'); 28 | const util = require('util'); 29 | 30 | 31 | (async () => { 32 | try { 33 | //Get the contests 34 | const contestsResponse = await got('https://www.draftkings.com/lobby/getcontests?sport=LOL'); 35 | const contestsJson = JSON.parse(contestsResponse.body); 36 | 37 | //Loop through all contests and build a list of the unique draft groups 38 | let groupIdList = []; 39 | contestsJson['Contests'].forEach(contest => { 40 | if (!groupIdList.includes(contest['dg'])) { 41 | groupIdList.push(contest['dg']) 42 | } 43 | }); 44 | 45 | //For each draft group, grab the draftables by replacing the parameter in the URL with the correct group Id 46 | for (const groupId of groupIdList) { 47 | console.log(groupId); 48 | const draftablePlayersResponse = await got(util.format('https://api.draftkings.com/draftgroups/v1/draftgroups/%s/draftables', groupId)); 49 | const draftableplayersJson = JSON.parse(draftablePlayersResponse.body); 50 | 51 | //Nice! Now we have the players so let's just console.log them as a simple example 52 | draftableplayersJson['draftables'].forEach(player => { 53 | console.log(player['displayName']); 54 | console.log(player['position']); 55 | console.log(player['salary']); 56 | console.log('***') 57 | }); 58 | } 59 | 60 | } catch (error) { 61 | console.log(error); 62 | } 63 | })(); 64 | 65 | ``` 66 | 67 | ## API Documentation 68 | All parameters are query string. 69 | 70 | ### **Get Contests** 71 | The fundamental endpoint. Contains wide ranging data from Contests, GameSets, GameTypes, DraftGroups, and other ancillary data. 72 | 73 | #### Endpoint 74 | https://www.draftkings.com/lobby/getcontests 75 | 76 | #### Parameters 77 | 1. Sport: Not required. List of valid values available from ['regionAbbreviatedSportName'] in https://api.draftkings.com/sites/US-DK/sports/v1/sports?format=json 78 | 79 | #### Example 80 | https://www.draftkings.com/lobby/getcontests?sport=LOL 81 | 82 | 83 | ### **Detailed Contest Information** 84 | Provides lowest level granularity of detail on a single contest. Helpful endpoint because it provides redundant data points with GetContests but in a more readable format. 85 | 86 | #### Endpoint 87 | https://api.draftkings.com/contests/v1/contests/[ContestId]?format=json 88 | 89 | #### Parameters 90 | 1. ContestId - Obtainable from the GetContests endpoint. Also visible throughout the site in the URL patterns through the frontend. 91 | 92 | #### Example 93 | https://api.draftkings.com/contests/v1/contests/105502444?format=json 94 | 95 | 96 | ### **Get DraftGroups** 97 | More detailed information on the slate itself including start time and all of the games/matches contained within the slate. 98 | 99 | #### Endpoint 100 | https://api.draftkings.com/draftgroups/v1/[draftGroupId] 101 | 102 | #### Parameters 103 | 1. DraftGroupId - A list of DraftGroupIds is obtainable from the GetContests call. 104 | 105 | #### Example 106 | https://api.draftkings.com/draftgroups/v1/46589 107 | 108 | 109 | ### **Get Rulesets** 110 | Detailed ruleset for a particular game type. 111 | 112 | #### Endpoint 113 | https://api.draftkings.com/lineups/v1/gametypes/[gameTypeId]/rules 114 | 115 | #### Parameters 116 | 1. GameTypeId - I don't know if there is an API that serves this up comprehensively. I've seen it towards the end of the GetContests call but I don't know if that just lists all Game Types available currently across all contests or if it's a full list. 117 | 118 | #### Example 119 | https://api.draftkings.com/lineups/v1/gametypes/1/rules 120 | 121 | 122 | ### **Get Draftable Players** 123 | 124 | #### Endpoint 125 | https://api.draftkings.com/draftgroups/v1/draftgroups/[draftGroupId]/draftables 126 | 127 | #### Parameters 128 | 1. DraftGroupId - Obtaining this ID is detailed elsewhere. 129 | 130 | #### Example 131 | https://api.draftkings.com/draftgroups/v1/draftgroups/46589/draftables 132 | 133 | 134 | ### **Get Available Players** 135 | Metadata, imagery, and other obscure information regarding individual players related to slate. Found to be of limited use. 136 | 137 | #### Endpoint 138 | https://www.draftkings.com/lineup/getavailableplayers?draftGroupId=[draftGroupId] 139 | 140 | #### Parameters 141 | 1. DraftGroupId - Obtaining this ID is detailed elsewhere. 142 | 143 | #### Example 144 | https://www.draftkings.com/lineup/getavailableplayers?draftGroupId=46887 145 | 146 | 147 | ### **Get Countries** 148 | Returns countries licensed to use the Draft Kings service? No idea how this would be helpful. 149 | 150 | #### Endpoint 151 | https://api.draftkings.com/addresses/v1/countries 152 | 153 | #### Parameters 154 | None. 155 | 156 | #### Example 157 | https://api.draftkings.com/addresses/v1/countries 158 | 159 | 160 | ### **Get Regions** 161 | Returns regions in the US where the service is legal to use? Also of limited use. 162 | 163 | #### Endpoint 164 | https://api.draftkings.com/addresses/v1/countries/[countryCode]regions 165 | 166 | #### Parameters 167 | 1. CountryCode - Obtainable from Get Countries. 168 | 169 | #### Example 170 | https://api.draftkings.com/addresses/v1/countries/US/regions 171 | 172 | 173 | ### **Get Rules and Scoring** 174 | Return HTML version of the rules and scoring. Obviously. 175 | 176 | #### Endpoint 177 | https://api.draftkings.com/rules-and-scoring/RulesAndScoring.json 178 | 179 | #### Parameters 180 | None. 181 | 182 | #### Example 183 | https://api.draftkings.com/rules-and-scoring/RulesAndScoring.json 184 | 185 | 186 | ### **Get Sports** 187 | Return all sports currently offered by Draft Kings in addition to some IDs and other codes for each sport. 188 | 189 | #### Endpoint 190 | https://api.draftkings.com/sites/US-DK/sports/v1/sports 191 | 192 | #### Parameters 193 | None. 194 | 195 | #### Example 196 | https://api.draftkings.com/sites/US-DK/sports/v1/sports 197 | 198 | 199 | 200 | ## Contact Information 201 | 202 | Pick your poison at https://seandrum.github.io/. --------------------------------------------------------------------------------