Sportradar
Stay organized with collections
Save and categorize content based on your preferences.
Retrieve a list of fixtures for the English Premier League
/**
* @fileoverview Example of using Sportsradar API to get English Premier League
* soccer schedules, to use in adjusting campaigns.
* The principles of this example could easily be reused against any of the
* sports feeds available from Sportradar.
*
* Example: Get fixtures on 1st Oct 2016
* const schedule = getSoccerSchedule(2016, 10, 1);
*
* See https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#working_with_api_responses
* See http://developer.sportradar.us/
*/
//
Replace
with
the
API
Key
found
on
your
Sportradar
API
Application
page
.
const
API_KEY
=
'ENTER_API_KEY'
;
//
Insert
your
email
address
here
for
notification
of
API
request
failures
.
const
EMAIL_ADDRESS
=
'ENTER_EMAIL_ADDRESS'
;
const
VERSION
=
2
;
const
LEAGUE
=
'eu'
;
//
Set
to
false
when
no
longer
in
trial
mode
.
const
TRIAL_MODE
=
true
;
/**
* Retrieves a list of fixtures from the Soccer Schedule API.
* @param {number} year The year for which to get matches, in the form yyyy.
* @param {number} month The month for which to get matches, in range 1-12.
* @param {number} day The day for which to get matches, in range 1-31.
* @return {!Array.<!Object>} An array of object containing fixture info or
* null if the request was unsuccessful.
*/
function
getSoccerSchedule
(
year
,
month
,
day
)
{
const
urlTemplate
=
'https://api.sportradar.us/soccer-%s%d/%s/matches/%d/%02d/%02d/schedule.xml?api_key=%s'
;
const
accessLevel
=
TRIAL_MODE
?
't'
:
'p'
;
const
url
=
Utilities
.
formatString
(
urlTemplate
,
accessLevel
,
VERSION
,
LEAGUE
,
year
,
month
,
day
,
API_KEY
);
const
response
=
UrlFetchApp
.
fetch
(
url
);
return
parseScheduleXml
(
response
.
getContentText
());
}
/**
* Converts the date format returned from the XML feed into a Date object.
* @param {string} scheduleDate A date from the feed e.g. 2016-07-11T17:00:00Z
* @return {!Date} The resulting Date object.
*/
function
parseScheduleDate
(
scheduleDate
)
{
return
new
Date
(
scheduleDate
.
replace
(
/-/
g
,
'/'
).
replace
(
'T'
,
' '
).
replace
(
'Z'
,
' GMT'
));
}
/**
* Parses the schedule XML, identifying only English Premier League Soccer
* matches, as an example of selecting events on which to make Google Ads
* changes.
* @param {string} xmlText XML response body from a call to the soccer schedule
* API.
* @return {!Array.<!Object>} An array of object containing fixture info.
*/
function
parseScheduleXml
(
xmlText
)
{
const
fixtures
=
[]
;
const
scheduleElement
=
XmlService
.
parse
(
xmlText
).
getRootElement
();
//
The
namespace
is
required
for
accessing
child
elements
in
the
schema
.
const
namespace
=
scheduleElement
.
getNamespace
();
const
matchesElement
=
scheduleElement
.
getChild
(
'matches'
,
namespace
);
const
matchElements
=
matchesElement
.
getChildren
();
for
(
let
i
=
0
,
matchElement
;
matchElement
=
matchElements
[
i
]
;
i
++
)
{
const
status
=
matchElement
.
getAttribute
(
'status'
).
getValue
();
const
scheduled
=
matchElement
.
getAttribute
(
'scheduled'
).
getValue
();
const
scheduledDate
=
parseScheduleDate
(
scheduled
);
const
categoryElement
=
matchElement
.
getChild
(
'category'
,
namespace
);
const
country
=
categoryElement
.
getAttribute
(
'country'
).
getValue
();
const
tournamentElement
=
matchElement
.
getChild
(
'tournament'
,
namespace
);
const
tournamentName
=
tournamentElement
.
getAttribute
(
'name'
).
getValue
();
if
(
tournamentName
===
'Premier League'
&&
country
===
'England'
)
{
const
homeElement
=
matchElement
.
getChild
(
'home'
,
namespace
);
const
awayElement
=
matchElement
.
getChild
(
'away'
,
namespace
);
const
homeTeamName
=
homeElement
.
getAttribute
(
'name'
).
getValue
();
const
awayTeamName
=
awayElement
.
getAttribute
(
'name'
).
getValue
();
fixtures
.
push
(
{
date
:
scheduledDate
,
homeTeam
:
homeTeamName
,
awayTeam
:
awayTeamName
}
);
}
}
return
fixtures
;
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThis script retrieves English Premier League soccer fixtures for a specific date using the Sportradar API.\u003c/p\u003e\n"],["\u003cp\u003eIt processes the API response, extracting match details like date, home team, and away team.\u003c/p\u003e\n"],["\u003cp\u003eThe script focuses solely on Premier League matches played in England, filtering out other leagues or tournaments.\u003c/p\u003e\n"],["\u003cp\u003eUsers need to replace placeholders for the API key and email address for the script to function correctly.\u003c/p\u003e\n"],["\u003cp\u003eIt utilizes the \u003ccode\u003eUrlFetchApp\u003c/code\u003e to make API requests and the \u003ccode\u003eXmlService\u003c/code\u003e to parse the XML response data.\u003c/p\u003e\n"]]],[],null,["# Sportradar\n\nRetrieve a list of fixtures for the English Premier League\n----------------------------------------------------------\n\n```transact-sql\n/**\n * @fileoverview Example of using Sportsradar API to get English Premier League\n * soccer schedules, to use in adjusting campaigns.\n * The principles of this example could easily be reused against any of the\n * sports feeds available from Sportradar.\n *\n * Example: Get fixtures on 1st Oct 2016\n * const schedule = getSoccerSchedule(2016, 10, 1);\n *\n * See https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#working_with_api_responses\n * See http://developer.sportradar.us/\n */\n\n// Replace with the API Key found on your Sportradar API Application page.\nconst API_KEY = 'ENTER_API_KEY';\n\n// Insert your email address here for notification of API request failures.\nconst EMAIL_ADDRESS = 'ENTER_EMAIL_ADDRESS';\n\nconst VERSION = 2;\nconst LEAGUE = 'eu';\n\n// Set to false when no longer in trial mode.\nconst TRIAL_MODE = true;\n\n/**\n * Retrieves a list of fixtures from the Soccer Schedule API.\n * @param {number} year The year for which to get matches, in the form yyyy.\n * @param {number} month The month for which to get matches, in range 1-12.\n * @param {number} day The day for which to get matches, in range 1-31.\n * @return {!Array.\u003c!Object\u003e} An array of object containing fixture info or\n * null if the request was unsuccessful.\n */\nfunction getSoccerSchedule(year, month, day) {\n const urlTemplate =\n 'https://api.sportradar.us/soccer-%s%d/%s/matches/%d/%02d/%02d/schedule.xml?api_key=%s';\n const accessLevel = TRIAL_MODE ? 't' : 'p';\n const url = Utilities.formatString(\n urlTemplate, accessLevel, VERSION, LEAGUE, year, month, day, API_KEY);\n const response = UrlFetchApp.fetch(url);\n return parseScheduleXml(response.getContentText());\n}\n\n/**\n * Converts the date format returned from the XML feed into a Date object.\n * @param {string} scheduleDate A date from the feed e.g. 2016-07-11T17:00:00Z\n * @return {!Date} The resulting Date object.\n */\nfunction parseScheduleDate(scheduleDate) {\n return new Date(\n scheduleDate.replace(/-/g, '/').replace('T', ' ').replace('Z', ' GMT'));\n}\n\n/**\n * Parses the schedule XML, identifying only English Premier League Soccer\n * matches, as an example of selecting events on which to make Google Ads\n * changes.\n * @param {string} xmlText XML response body from a call to the soccer schedule\n * API.\n * @return {!Array.\u003c!Object\u003e} An array of object containing fixture info.\n */\nfunction parseScheduleXml(xmlText) {\n const fixtures = [];\n const scheduleElement = XmlService.parse(xmlText).getRootElement();\n // The namespace is required for accessing child elements in the schema.\n const namespace = scheduleElement.getNamespace();\n const matchesElement = scheduleElement.getChild('matches', namespace);\n\n const matchElements = matchesElement.getChildren();\n for (let i = 0, matchElement; matchElement = matchElements[i]; i++) {\n const status = matchElement.getAttribute('status').getValue();\n\n const scheduled = matchElement.getAttribute('scheduled').getValue();\n const scheduledDate = parseScheduleDate(scheduled);\n const categoryElement = matchElement.getChild('category', namespace);\n const country = categoryElement.getAttribute('country').getValue();\n const tournamentElement = matchElement.getChild('tournament', namespace);\n const tournamentName = tournamentElement.getAttribute('name').getValue();\n if (tournamentName === 'Premier League' && country === 'England') {\n const homeElement = matchElement.getChild('home', namespace);\n const awayElement = matchElement.getChild('away', namespace);\n\n const homeTeamName = homeElement.getAttribute('name').getValue();\n const awayTeamName = awayElement.getAttribute('name').getValue();\n\n fixtures.push({\n date: scheduledDate,\n homeTeam: homeTeamName,\n awayTeam: awayTeamName\n });\n }\n }\n return fixtures;\n}\n```"]]