Retrieve leagues that the user belongs to in one or more games. The leagues will be scoped to the user. This will throw an error if any of the specified games do not support league sub-resources. Users must be authenticated in order to use this endpoint.
const YahooFantasy = require('yahoo-fantasy');
const yf = new YahooFantasy(
Y!APPLICATION_KEY,
Y!APPLICATION_SECRET,
tokenCallbackFn, // optional
redirectUri // optional
);
yf.setUserToken(
Y!OAuthAccessToken
);
// promise based
try {
const players = await yf.user.game_leagues(game_key);
} catch (e) {
// handle error
}
// callback based
yf.user.game_leagues(game_key, callbackFn);
{
"guid": "RYWP7M53IC626MGOX36ZWCM4FA",
"leagues": [
{
"game_key": "328",
"game_id": "328",
"name": "Baseball",
"code": "mlb",
"type": "full",
"url": "http://baseball.fantasysports.yahoo.com/b1",
"season": "2014",
"leagues": [
{
"league_key": "328.l.24281",
"league_id": "24281",
"name": "FKL Baseball - Season VIII",
"url": "http://baseball.fantasysports.yahoo.com/b1/24281",
"draft_status": "postdraft",
"num_teams": 13,
"edit_key": "2014-11-15",
"weekly_deadline": "intraday",
"league_update_timestamp": "1411977871",
"scoring_type": "point",
"league_type": "private",
"renew": "308_5853",
"renewed": "",
"short_invitation_url": "https://yho.com/mlb?l=24281&k=ca97a25b0913fcb3",
"is_pro_league": "0",
"start_date": "2014-03-22",
"end_date": "2014-09-28",
"is_finished": 1
},
{
"league_key": "328.l.34014",
"league_id": "34014",
"name": "Freddy Beach Baseball",
"url": "http://baseball.fantasysports.yahoo.com/b1/34014",
"password": "",
"draft_status": "postdraft",
"num_teams": 12,
"edit_key": "2014-11-15",
"weekly_deadline": "intraday",
"league_update_timestamp": "1411979069",
"scoring_type": "head",
"league_type": "private",
"renew": "308_51222",
"renewed": "",
"short_invitation_url": "https://yho.com/mlb?l=34014&k=0a2bf56970bb200c",
"is_pro_league": "0",
"current_week": "25",
"start_week": "1",
"start_date": "2014-03-22",
"end_week": "25",
"end_date": "2014-09-28",
"is_finished": 1
}
]
},
{
"game_key": "341",
"game_id": "341",
"name": "Hockey",
"code": "nhl",
"type": "full",
"url": "http://hockey.fantasysports.yahoo.com/hockey",
"season": "2014",
"leagues": [
{
"league_key": "341.l.21063",
"league_id": "21063",
"name": "theREDleague",
"url": "http://hockey.fantasysports.yahoo.com/hockey/21063",
"password": "",
"draft_status": "postdraft",
"num_teams": 14,
"edit_key": "2014-11-15",
"weekly_deadline": "intraday",
"league_update_timestamp": "1416042475",
"scoring_type": "point",
"league_type": "private",
"renew": "321_63055",
"renewed": "",
"short_invitation_url": "https://yho.com/nhl?l=21063&k=7a5b54fa3927ebc2",
"is_pro_league": "0",
"start_date": "2014-10-08",
"end_date": "2015-04-11"
}
]
}
]
}