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.
The Media Broadcast RESTful API provides the following functions:
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.
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.
- 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.
You can ban or unban a live stream and query stream information and statistics.
- 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.
Standard recording supports creating clips and snapshots out of a recording file.
Follow these steps to call the Media Broadcast RESTful API:
- Add the stream-pushing domain name and the stream-playing domain name.
- (Optional) Add an entry point.
This step is optional. Agora provides a default entry point that you can use directly.
- Call the API to configure streaming functions as needed.
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 :
_30from hashlib import sha256
_30# The App ID of your Agora project
_30# Get Customer ID in the RESTful API of the Agora Console
_30customer_username = ''
_30# Get Customer Secret in the RESTful API of the Agora Console
_30# Request method and endpoint
_30path = f'/v1/projects/{appid}/fls/domains'
_30body_sha256 = sha256(data.encode('utf-8')).digest()
_30body_sha256_base64 = base64.b64encode(body_sha256)
_30date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
_30request_line = "{} {} {}".format(req_metd, path, "HTTP/1.1")
_30digest = "SHA-256={}".format(body_sha256_base64.decode("utf-8"))
_30signing_string = "host: {}\ndate: {}\n{}\ndigest: {}".format(host, date, request_line, digest)
_30signature = base64.b64encode(
_30 hmac.new(customer_secret.encode("utf-8"), signing_string.encode("utf-8"), sha256).digest())
_30authorization = 'hmac username="{}", algorithm="hmac-sha256", headers="host date request-line digest", signature="{}"'.format(
_30 customer_username, signature.decode("utf-8"))
All requests are sent to the following host: api.agora.io
.
To ensure communication security, the Media Broadcast RESTful API only supports the HTTPS protocol.
- 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.
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?.
This section provides complete code samples for calling the Media Broadcast RESTful API.
_44from hashlib import sha256
_44customer_username = "hmac_user_name"
_44customer_secret = "hmac_user_secret"
_44stream_name = "stream_name"
_44customer_data = json.dumps({"resumeTime":"2023-11-29T19:00:00+08:00"})
_44body_sha256 = sha256(customer_data.encode('utf-8')).digest()
_44body_sha256_base64 = base64.b64encode(body_sha256)
_44path = "/v1/projects/%s/fls/entry_points/live/admin/banned_streams/%s" % (appid, stream_name)
_44date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
_44request_line = "{} {} {}".format("PATCH", path, "HTTP/1.1")
_44digest = "SHA-256={}".format(body_sha256_base64.decode("utf-8"))
_44signing_string = "host: {}\ndate: {}\n{}\ndigest: {}".format(host, date, request_line, digest)
_44signature = base64.b64encode(hmac.new(customer_secret.encode("utf-8"), signing_string.encode("utf-8"), sha256).digest())
_44authorization = 'hmac username="{}", algorithm="hmac-sha256", headers="host date request-line digest", signature="{}"'.format(customer_username, signature.decode("utf-8"))
_44 "authorization": authorization,
_44response = requests.patch("https://{}{}".format(host, path), headers=headers, data=customer_data)
_44print(response.status_code, response.content.decode())
_44print(response.headers)
_87import javax.crypto.Mac;
_87import javax.crypto.spec.SecretKeySpec;
_87import java.net.HttpURLConnection;
_87import java.net.MalformedURLException;
_87import java.nio.charset.StandardCharsets;
_87import java.security.InvalidKeyException;
_87import java.security.MessageDigest;
_87import java.security.NoSuchAlgorithmException;
_87import java.text.SimpleDateFormat;
_87public class GatewayKey {
_87 public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException {
_87 String customerUsername = "hmac_user_name";
_87 String customerSecret = "hmac_user_secret";
_87 String customerData = "";
_87 String appid = "your_appid";
_87 String streamName = "stream_name";
_87 String requestMethod = "DELETE";
_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 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 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 String signingString = String.format("host: %s\ndate: %s\n%s\ndigest: %s", host, date, requestLine, digest);
_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 System.out.println(authorization);
_87 System.out.println(signingString);
_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 OutputStream stream = http.getOutputStream();
_87 stream.write(customerData.getBytes("UTF-8"));
_87 System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
_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 br = new BufferedReader(new InputStreamReader(http.getErrorStream()));
_87 String strCurrentLine;
_87 while ((strCurrentLine = br.readLine()) != null) {
_87 System.out.println(strCurrentLine);
_42var crypto = require("crypto");
_42var request = require("request");
_42var customer_username = "{your_hmac_key}";
_42var customer_secret = "{your_hmac_secret}";
_42var host = "api.agora.io";
_42var path = "/v1/projects/{appid}/fls/entry_points/live/admin/banned_streams/{streamName}";
_42content.resumeTime = "2023-11-29T19:00:00+08:00";
_42var contentString = JSON.stringify(content);
_42gmt_date = new Date().toGMTString();
_42digest = "SHA-256=" + Buffer.from(crypto.createHash("sha256").update(contentString).digest()).toString("base64");
_42request_line = method + " " + path + " " + "HTTP/1.1";
_42signing_string = "host: " + host;
_42signing_string = signing_string + "\ndate: " + gmt_date;
_42signing_string = signing_string + "\n" + request_line;
_42signing_string = signing_string + "\ndigest: " + digest;
_42signature = crypto.createHmac("sha256", customer_secret).update(signing_string).digest();
_42signature = Buffer.from(signature).toString("base64");
_42authorization = 'hmac username="' + customer_username + '", ';
_42authorization = authorization + 'algorithm="hmac-sha256", headers="host date request-line digest", signature="';
_42authorization = authorization + signature + '"';
_42 url: "https://" + host + path,
_42 headers: {"content-type": "application/json", date: gmt_date, digest: digest, authorization: authorization},
_42 function (err, res, body) {
_42 console.log("err:", err);
_42 console.log("status:", res.statusCode);
_42 console.log("body:", body);
_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$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$request_lint = sprintf("%s %s %s", $request_method, $path, "HTTP/1.1");
_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$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 "authorization: $authorization",
_51var_dump(getCurl("https://$host$path", $header, $request_method, $data));
_51function getCurl($url, $headerArray, $method, $data){
_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 $output = json_decode($output,true);
_22var customer_username = "hmac_user_name"
_22var customer_secret = "hmac_user_secret"
_22gmt_date = new Date().toGMTString()
_22digest = "SHA-256=" + CryptoJS.enc.Base64.stringify(CryptoJS.SHA256(pm.request.body.raw))
_22request_line = pm.request.method + " " + pm.request.url.getPath() + " " + "HTTP/1.1"
_22signing_string = "host: " + pm.request.url.getHost()
_22signing_string = signing_string + "\ndate: " + gmt_date
_22signing_string = signing_string + "\n" + request_line
_22signing_string = signing_string + "\ndigest: " + digest
_22signature = CryptoJS.HmacSHA256(signing_string, customer_secret)
_22signature = CryptoJS.enc.Base64.stringify(signature)
_22authorization = 'hmac username="' + customer_username + '", '
_22authorization = authorization + 'algorithm="hmac-sha256", headers="host date request-line digest", signature="'
_22authorization = authorization + signature + '"'
_22pm.request.headers.add({key: 'date', value: gmt_date})
_22pm.request.headers.add({key: 'digest', value: digest})
_22pm.request.headers.add({key: 'authorization', value: authorization})