How to get League & Cup Profile (Basic) - Football API sample code
Posted on June 12, 2020
Share the sample code using the interface call of iSports Api Sports Data www.isportsapi.com. This API endpoint returns the basic information of football leagues and cups.
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class SportDemo {
public static void main(String[] args) {
// Set url parameter
String url = "http://api.isportsapi.com/sport/football/league/basic?api_key=<YOUR_API_KEY>";
// Call iSport Api to get data in json format
String charset = "UTF-8";
String jsonResult = get(url, charset);
System.out.println(jsonResult);
}
/**
* @param url
* @param charset
* @return return json string
*/
public static String get(String url, String charset) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
try {
URL newUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection)newUrl.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(30000);
connection.setConnectTimeout(30000);
connection.setRequestProperty("User-agent", userAgent);
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, charset));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
result = sbf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
The football API returns the data as follows:
{
"code": 0,
"message": "success",
"data": [
{
"leagueId": "111",
"name": "Ireland Premier Division",
"shortName": "IRE PR",
"type": 1,
"subLeagueName": "League"
},
{
"leagueId": "122",
"name": "Argentine Division 1",
"shortName": "ARG D1",
"type": 1,
"subLeagueName": "League"
},
{
"leagueId": "133",
"name": "Austrian Bundesliga",
"shortName": "AUT D1",
"type": 1,
"subLeagueName": ""
},
{
"leagueId": "144",
"name": "Brazil Serie A",
"shortName": "BRA D1",
"type": 1,
"subLeagueName": ""
}
]
}
Recommended Reading

What is the best way to know about soccer live score?
Football/soccer is one game that appreciates support from individuals of all social statuses and ages from around the world. Because of its ubiquity, millions go to arenas or sit before their TVs to observe a standoff of their preferred groups. For the love and the enthusiasm of this wonderful game

Free Trial Sports API Let You Drive The Technology
Since iSports API’s launch in the early 21th centuary, it has developed into the world’s leading provider of sports data products and services. iSports API's radar is 360-degree portfolio includes everything a bookmaker, no matter how large or small, needs to run a successful business, including da

How does a high quality sports data API work?
iSports API Data Feeds is the complete and time-tested sports data solution for delivering betting odds, scores, and real-time settlements, covering all major sports events, specially designed to help bookmakers and platform providers diversify their offering. With successfully resolved cases and t