In the code samples below, remember to replace YOUR_API_KEY with your API key and END_USER_IP_ADDRESS with the IP address of the end user who will watch the stream.
The code samples below are examples showing how to call the GET /events endpoint to get a list of events with available streams by filtering the stream status with "On Air Broadcast" (stream_status=av:stream_status:2).
They also show how to find the right stream IDs for the following streams:
av:product:2 (LCO), content variant av:content_variant:1 (Standard feed) and distribution av:distribution:1 (Live).av:product:2 (LCO), content variant av:content_variant:2 (4Sight Streaming feed) and distribution av:distribution:1 (Live).av:product:8 (Live Channel Promotion Premium) and distribution av:distribution:3 (VOD).These stream IDs can then be used to get a stream URL (see code samples in the next section).
Important: the data provided by this endpoint is cached for 1 minute. Therefore, there is no need to call this endpoint more than once per minute.
The code samples below are examples showing how to call the GET /streams/<stream_id>/<stream_type> endpoint in order to get the URL of a stream, knowing its stream ID. The requested stream type in these examples is HLS manifest. When requesting this endpoint, the "client side ID" must be passed in the query string parameter csid.
Tip: Some other query string parameters can be used in the request. Please see the documentation of this endpoint for more details.
<?php
try {
$token = "YOUR_API_KEY";
$baseUrl = "https://av-api.betradar.com";
$streamStatus = "av:stream_status:2";
$streamIds = [
'lco_live_standard' => [],
'lco_live_4sight' => [],
'lcp_vod_clip' => []
];
$response = file_get_contents("$baseUrl/events?stream_status=$streamStatus", false, stream_context_create([
"http" => [
"header" => "Authorization: Bearer $token"
]
]));
if ($response === false) {
throw new Exception("Failed to fetch data from API.");
}
$response = json_decode($response, true);
if ($response === null) {
throw new Exception("Failed to decode JSON response.");
}
foreach ($response as $event) {
foreach ($event['contents'] as $content) {
$contentVariantId = $content['content_variant']['id'] ?? null;
foreach ($content['streams'] as $stream) {
$productId = $stream['product']['id'] ?? null;
$distributionId = $stream['distribution']['id'] ?? null;
if ($contentVariantId === 'av:content_variant:1' && $productId === 'av:product:2' && $distributionId === 'av:distribution:1') {
$streamIds['lco_live_standard'] = $stream['id'];
}
if ($contentVariantId === 'av:content_variant:2' && $productId === 'av:product:2' && $distributionId === 'av:distribution:1') {
$streamIds['lco_live_4sight'] = $stream['id'];
}
if ($productId === 'av:product:8' && $distributionId === 'av:distribution:3') {
$streamIds['lcp_vod_clip'] = $stream['id'];
}
}
}
}
return $streamIds;
} catch (Exception $e) {
return ['error' => $e->getMessage()];
}
?>Tip: Some other query string parameters can be used in the request. Please see the documentation of this endpoint for more details.
<?php
$token = "YOUR_API_KEY";
$ip = "END_USER_IP_ADDRESS";
$baseUrl = "https://av-api.betradar.com";
$streamId = "av:stream:123";
$csid = "actual_csid";
try {
$response = file_get_contents("$baseUrl/streams/$streamId/hls-manifest?csid=$csid", false, stream_context_create([
"http" => [
"header" => "Authorization: Bearer $token\r\nX-Real-IP: $ip"
]
]));
if ($response === false) {
throw new Exception("Failed to fetch data from API.");
}
$response = json_decode($response, true);
if ($response === null) {
throw new Exception("Failed to decode JSON response.");
}
return $response['url'] ?? null;
} catch (Exception $e) {
return ['error' => $e->getMessage()];
}
?>