Skip to main content

API overview

With the Agora Media Broadcast RESTful API, you can configure and manage the streaming service at your server by sending HTTP requests to Agora servers.

This page is a basic introduction to the Media Broadcast RESTful API.

Media Broadcast is currently in public beta. To enable this service, contact sales@agora.io.

Functions

The Media Broadcast RESTful API provides the following functions:

Domain name and entry-point management

There are two types of domain names: Stream-pushing domain names and stream-playing domain names. They mainly affect regional access and stream scheduling. The same live stream can be pushed or played through multiple different domain names.

Entry points are used to group live streams. Once you configure a function such as recording, transcoding, or snapshot capturing for an entry point, that configuration applies to all live streams under this entry point.

Stream recording

You can record the content of a live stream into MP4 and HLS files and upload these files to a third-party cloud storage service.

Stream processing

  • Snapshot and content moderation: You can get snapshots of a live stream at regular intervals and upload them to a third-party cloud storage service or a content moderation service.
  • Transcoding: Transcoding a live stream modifies the audio and video encoder configuration, using either the preset templates or a custom configuration.
  • Watermark: Adding a watermark to a live stream takes effect on both the original stream and the transcoded stream.

Stream management

You can ban or unban a live stream and query stream information and statistics.

Stream authentication

  • Timestamp authentication: Set an authentication key for a stream-pushing or stream-playing domain name.
  • Origin authentication: Send authentication requests to your origin server synchronously or asynchronously. You can also cache the authentication results.

Recording processing

Standard recording supports creating clips and snapshots out of a recording file.

Implementation

Follow these steps to call the Media Broadcast RESTful API:

  1. Add the stream-pushing domain name and the stream-playing domain name.
  2. (Optional) Add an entry point. This step is optional. Agora provides a default entry point that you can use directly.
  3. Call the API to configure streaming functions as needed.

Request structure

Authentication

The Media Broadcast RESTful API uses HTTP HMAC (Hash-based Message Authentication Code) authentication.

When you send an HTTP request, you need to generate a signature using the HMAC-SHA256 algorithm and pass this signature and its related information to the authorization field.

You need the following Agora account information to generate the authentication field:

To show you how to generate the value of the authorization field, the following Python code (Python 3.7+) takes the API that lists domain names as an example :


_30
import hmac
_30
import base64
_30
import datetime
_30
from hashlib import sha256
_30
_30
# The App ID of your Agora project
_30
appid = ''
_30
# Get Customer ID in the RESTful API of the Agora Console
_30
customer_username = ''
_30
# Get Customer Secret in the RESTful API of the Agora Console
_30
customer_secret = ''
_30
# Request body
_30
data = ""
_30
_30
# Request host
_30
host = "api.agora.io"
_30
# Request method and endpoint
_30
req_metd = 'GET'
_30
path = f'/v1/projects/{appid}/fls/domains'
_30
_30
body_sha256 = sha256(data.encode('utf-8')).digest()
_30
body_sha256_base64 = base64.b64encode(body_sha256)
_30
date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
_30
request_line = "{} {} {}".format(req_metd, path, "HTTP/1.1")
_30
digest = "SHA-256={}".format(body_sha256_base64.decode("utf-8"))
_30
signing_string = "host: {}\ndate: {}\n{}\ndigest: {}".format(host, date, request_line, digest)
_30
signature = base64.b64encode(
_30
hmac.new(customer_secret.encode("utf-8"), signing_string.encode("utf-8"), sha256).digest())
_30
authorization = 'hmac username="{}", algorithm="hmac-sha256", headers="host date request-line digest", signature="{}"'.format(
_30
customer_username, signature.decode("utf-8"))

Server address

All requests are sent to the following host: api.agora.io.

Protocol

To ensure communication security, the Media Broadcast RESTful API only supports the HTTPS protocol.

Data format

  • Request: Refer to the example for each API endpoint.
  • Response: The format of responses is JSON.

All request URLs and request body content is case-sensitive.

API limit

The call frequency limit of the Media Broadcast RESTful API is 50 times per second. If the call frequency exceeds the limit, see How can I avoid being frequency limited when calling Agora Server RESTful APIs?.

Code samples

This section provides complete code samples for calling the Media Broadcast RESTful API.

Python


_44
import hmac
_44
import base64
_44
import datetime
_44
import requests
_44
import json
_44
from hashlib import sha256
_44
_44
# username
_44
customer_username = "hmac_user_name"
_44
# secret
_44
customer_secret = "hmac_user_secret"
_44
# appid
_44
appid = "your_appid"
_44
# streamName
_44
stream_name = "stream_name"
_44
# content
_44
customer_data = json.dumps({"resumeTime":"2023-11-29T19:00:00+08:00"})
_44
_44
body_sha256 = sha256(customer_data.encode('utf-8')).digest()
_44
body_sha256_base64 = base64.b64encode(body_sha256)
_44
_44
host = "api.agora.io"
_44
path = "/v1/projects/%s/fls/entry_points/live/admin/banned_streams/%s" % (appid, stream_name)
_44
date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
_44
request_line = "{} {} {}".format("PATCH", path, "HTTP/1.1")
_44
digest = "SHA-256={}".format(body_sha256_base64.decode("utf-8"))
_44
_44
signing_string = "host: {}\ndate: {}\n{}\ndigest: {}".format(host, date, request_line, digest)
_44
signature = base64.b64encode(hmac.new(customer_secret.encode("utf-8"), signing_string.encode("utf-8"), sha256).digest())
_44
authorization = 'hmac username="{}", algorithm="hmac-sha256", headers="host date request-line digest", signature="{}"'.format(customer_username, signature.decode("utf-8"))
_44
print (authorization)
_44
_44
headers = {
_44
"host": host,
_44
"date": date,
_44
"digest": digest,
_44
"authorization": authorization,
_44
}
_44
_44
print(signing_string)
_44
_44
response = requests.patch("https://{}{}".format(host, path), headers=headers, data=customer_data)
_44
print(response.status_code, response.content.decode())
_44
print(response.headers)

Java


_87
import javax.crypto.Mac;
_87
import javax.crypto.spec.SecretKeySpec;
_87
import java.io.*;
_87
import java.net.HttpURLConnection;
_87
import java.net.MalformedURLException;
_87
import java.net.URL;
_87
import java.nio.charset.StandardCharsets;
_87
import java.security.InvalidKeyException;
_87
import java.security.MessageDigest;
_87
import java.security.NoSuchAlgorithmException;
_87
import java.text.SimpleDateFormat;
_87
import java.util.*;
_87
_87
_87
public class GatewayKey {
_87
_87
public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException {
_87
_87
String customerUsername = "hmac_user_name";
_87
String customerSecret = "hmac_user_secret";
_87
String customerData = "";
_87
_87
String appid = "your_appid";
_87
String streamName = "stream_name";
_87
String requestMethod = "DELETE";
_87
_87
MessageDigest messageDigest;
_87
messageDigest = MessageDigest.getInstance("SHA-256");
_87
messageDigest.update(customerData.getBytes("UTF-8"));
_87
String base64encodedString = Base64.getEncoder().encodeToString(messageDigest.digest());
_87
String digest = "SHA-256=" + base64encodedString;
_87
_87
String host = "api.agora.io";
_87
String path = String.format("/v1/projects/%s/fls/entry_points/live/admin/banned_streams/%s", appid, streamName);
_87
String requestLine = requestMethod + " " + path + " " + "HTTP/1.1";
_87
_87
final Date currentTime = new Date();
_87
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
_87
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
_87
String date = sdf.format(currentTime);
_87
_87
String signingString = String.format("host: %s\ndate: %s\n%s\ndigest: %s", host, date, requestLine, digest);
_87
_87
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
_87
SecretKeySpec secret_key = new SecretKeySpec(customerSecret.getBytes("UTF-8"), "HmacSHA256");
_87
sha256_HMAC.init(secret_key);
_87
String signature = Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(signingString.getBytes("UTF-8")));
_87
String authorization = String.format("hmac username=\"%s\", algorithm=\"hmac-sha256\", headers=\"host date request-line digest\", signature=\"%s\"",
_87
customerUsername, signature);
_87
_87
System.out.println(authorization);
_87
System.out.println(signingString);
_87
_87
URL url = new URL("https://" + host + path);
_87
HttpURLConnection http = (HttpURLConnection)url.openConnection();
_87
http.setRequestMethod("DELETE");
_87
http.setDoOutput(true);
_87
http.setRequestProperty("host", host);
_87
http.setRequestProperty("date", date);
_87
http.setRequestProperty("digest", digest);
_87
http.setRequestProperty("authorization", authorization);
_87
_87
OutputStream stream = http.getOutputStream();
_87
stream.write(customerData.getBytes("UTF-8"));
_87
_87
System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
_87
_87
_87
BufferedReader br = null;
_87
if (http.getResponseCode() == 200) {
_87
br = new BufferedReader(new InputStreamReader(http.getInputStream()));
_87
String strCurrentLine;
_87
while ((strCurrentLine = br.readLine()) != null) {
_87
System.out.println(strCurrentLine);
_87
}
_87
} else {
_87
br = new BufferedReader(new InputStreamReader(http.getErrorStream()));
_87
String strCurrentLine;
_87
while ((strCurrentLine = br.readLine()) != null) {
_87
System.out.println(strCurrentLine);
_87
}
_87
}
_87
_87
_87
http.disconnect();
_87
}
_87
}

Node.js


_42
var crypto = require("crypto");
_42
var request = require("request");
_42
_42
var customer_username = "{your_hmac_key}";
_42
var customer_secret = "{your_hmac_secret}";
_42
_42
var host = "api.agora.io";
_42
var path = "/v1/projects/{appid}/fls/entry_points/live/admin/banned_streams/{streamName}";
_42
var method = "PATCH";
_42
_42
var content = {};
_42
content.resumeTime = "2023-11-29T19:00:00+08:00";
_42
var contentString = JSON.stringify(content);
_42
_42
gmt_date = new Date().toGMTString();
_42
_42
digest = "SHA-256=" + Buffer.from(crypto.createHash("sha256").update(contentString).digest()).toString("base64");
_42
request_line = method + " " + path + " " + "HTTP/1.1";
_42
_42
signing_string = "host: " + host;
_42
signing_string = signing_string + "\ndate: " + gmt_date;
_42
signing_string = signing_string + "\n" + request_line;
_42
signing_string = signing_string + "\ndigest: " + digest;
_42
signature = crypto.createHmac("sha256", customer_secret).update(signing_string).digest();
_42
signature = Buffer.from(signature).toString("base64");
_42
_42
authorization = 'hmac username="' + customer_username + '", ';
_42
authorization = authorization + 'algorithm="hmac-sha256", headers="host date request-line digest", signature="';
_42
authorization = authorization + signature + '"';
_42
_42
request.patch(
_42
{
_42
url: "https://" + host + path,
_42
headers: {"content-type": "application/json", date: gmt_date, digest: digest, authorization: authorization},
_42
body: contentString,
_42
},
_42
function (err, res, body) {
_42
console.log("err:", err);
_42
console.log("status:", res.statusCode);
_42
console.log("body:", body);
_42
},
_42
);

PHP


_51
<?php
_51
_51
# Your Customer ID retrieved from Agora Console
_51
$customer_username = "{your username}";
_51
# Your Customer Secret retrieved from Agora Console
_51
$customer_secret = "{your secret}";
_51
# Your App ID retrieved from Agora Console
_51
$appid = "{your appid}";
_51
$request_method = "PATCH";
_51
# Requesy body
_51
$data = "";
_51
$host = "api.agora.io";
_51
$entry_point = "live";
_51
$path = sprintf("/v1/projects/%s/fls/entry_points/%s/reports/online_streams", $appid, $entry_point);
_51
$date = gmDate("D, d M Y H:i:s ", time()) . "GMT";
_51
_51
$request_lint = sprintf("%s %s %s", $request_method, $path, "HTTP/1.1");
_51
_51
$data = trim($data);
_51
$digest = 'SHA-256=' . base64_encode(pack("H*", hash("sha256", $data)));
_51
$signing_string = sprintf("host: %s\ndate: %s\n%s\ndigest: %s", $host,$date,$request_lint,$digest);
_51
_51
$signature = base64_encode(pack('H*', hash_hmac('sha256', $signing_string, $customer_secret)));
_51
$authorization = sprintf('hmac username="%s", algorithm="hmac-sha256", headers="host date request-line digest", signature="%s"', $customer_username, $signature);
_51
_51
$header = [
_51
"host: $host",
_51
"date: $date",
_51
"digest: $digest",
_51
"authorization: $authorization",
_51
];
_51
_51
var_dump($header);
_51
var_dump(getCurl("https://$host$path", $header, $request_method, $data));
_51
_51
_51
_51
function getCurl($url, $headerArray, $method, $data){
_51
$ch = curl_init();
_51
curl_setopt($ch, CURLOPT_URL, $url);
_51
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
_51
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
_51
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
_51
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $method);
_51
curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
_51
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
_51
$output = curl_exec($ch);
_51
curl_close($ch);
_51
$output = json_decode($output,true);
_51
return $output;
_51
}

Postman Pre-request Script


_22
var customer_username = "hmac_user_name"
_22
var customer_secret = "hmac_user_secret"
_22
_22
_22
gmt_date = new Date().toGMTString()
_22
digest = "SHA-256=" + CryptoJS.enc.Base64.stringify(CryptoJS.SHA256(pm.request.body.raw))
_22
request_line = pm.request.method + " " + pm.request.url.getPath() + " " + "HTTP/1.1"
_22
_22
signing_string = "host: " + pm.request.url.getHost()
_22
signing_string = signing_string + "\ndate: " + gmt_date
_22
signing_string = signing_string + "\n" + request_line
_22
signing_string = signing_string + "\ndigest: " + digest
_22
signature = CryptoJS.HmacSHA256(signing_string, customer_secret)
_22
signature = CryptoJS.enc.Base64.stringify(signature)
_22
_22
authorization = 'hmac username="' + customer_username + '", '
_22
authorization = authorization + 'algorithm="hmac-sha256", headers="host date request-line digest", signature="'
_22
authorization = authorization + signature + '"'
_22
_22
pm.request.headers.add({key: 'date', value: gmt_date})
_22
pm.request.headers.add({key: 'digest', value: digest})
_22
pm.request.headers.add({key: 'authorization', value: authorization})

Page Content