I have a global variable defined that will matchup to a "league_id" in the API.
I'm making ajax calls to post some forms and I don't know the correct server at the time , so i need to check the API , use the league_id that is know and get the corresponding url server.....width is the 2 digits after //www in each url path in the API.
Here is my ajax call , i have fiddled with this for hours and can't figure it out
var knownID = "32537";
var url = '//api.myfantasyleague.com/' + year + '/export?TYPE=myleagues&JSON=1';
function GetServerID() {
$.ajax({
url: url,
type: "GET",
dataType: 'json',
xhrFields: {
withCredentials: true
},
success: function (data) {
myLeagues = data.leagues.league;
// get the serverID that matched the "knownID" which is 32537 in this example
// the server id for this league is "46" - the 2 digits after "www" in the API url item
// set new variable that matches the serverID to the global variable "knowID"
}
});
}
API data
{"leagues":{"league":[
{"franchise_id":"0001","url":"https://www46.myfantasyleague.com/2022/home/32537","name":"Auction Draft","league_id":"32537"},
{"franchise_id":"0001","url":"https://www49.myfantasyleague.com/2022/home/41681","name":"Contest League Test","league_id":"41681"},
{"franchise_id":"0001","url":"https://www46.myfantasyleague.com/2022/home/43619","name":"Draft","league_id":"43619"},
{"franchise_id":"0000","url":"https://www48.myfantasyleague.com/2022/home/19048","name":"MFL Manager","league_id":"19048"}]
}}