REST quickstart
Cloud Recording enables you to record and store real-time audio and video streams from channels. To implement Cloud Recording, you set up a self-hosted backend that interacts with Agora servers to manage recording tasks. This guide introduces the essential Cloud Recording RESTful APIs you use to manage the recording process.
The command-line examples in this guide are for demonstration purposes only. Do not use them directly in a production environment. Implement RESTful API requests through your application server or use Agora's Go backend middleware. For details, see Quickstart using middleware
Understand the tech
The basic process of implementing Cloud Recording is as follows:
-
Get a resource ID
Before starting a cloud recording, call the
acquire
method to obtain a cloud recording resource ID. After calling this method successfully, you get a resource ID in the response body. -
Start cloud recording
Call the
start
method to join the channel and start a cloud recording. After calling this method successfully, you get a recording ID from the response body to identify the current recording process. -
Query the recording status
Call the
query
method to check the recording status during the recording. -
Stop cloud recording
Call the
stop
method to stop the cloud recording. -
Upload the recording file
After the recording ends, the cloud recording service uploads the recording file to the third-party cloud storage you specify.
Prerequisites
To implement Cloud Recording, ensure that you have:
-
A valid Agora account and project. Obtain the following parameters from Agora Console:
- The App ID and App certificate for your project. See Get Started with Agora
- A valid temporary token
- Customer ID and Customer key for RESTful API. See Authenticate REST calls
-
Set up and enabled a supported third-party cloud storage service. Obtain the following parameters for your storage:
- Bucket name
- Access key
- Secret key
Supported third-party cloud storage services
-
Enabled the Agora Cloud Recording service for your project.
Steps to enable cloud recording
- Log in to Agora Console, and click the Project Management icon on the left navigation panel.
- On the Project Management page, find the project for which you want to enable the cloud recording service, and click the edit icon.
- On the Edit Project page, find Cloud Recording, and click Enable.
On the following screen, click Enable Cloud Recording.
- Click Apply. Now, you can use Agora Cloud Recording and see the usage statistics in the Usage page.
-
If your network has a firewall, follow the instructions in Firewall Requirements.
Implement cloud recording
The following figure shows the API call sequence to start and manage cloud recording:
The following APIs are optional and can be called multiple times. However, they must be called during a recording session, that is, after recording starts and before it ends:
query
: Query the recording statusupdate
: Update the subscription listupdateLayout
: Update the video layout
Use basic HTTP authentication
The Cloud Recording RESTful APIs require basic HTTP authentication. You need to set the Authorization
parameter in every HTTP request header. For details, see Basic HTTP authentication.
Get a resource ID
Call the acquire
method to request a resource ID for Cloud Recording.
After calling this method successfully, you receive a resource ID in the response body. The resource ID is valid for five minutes. Start recording with this resource ID within the validity period. One resource ID can only be used for a single recording session.
-
The recording service is equivalent to a non-streaming client in the channel. The
uid
parameter in the request body is used to identify the recording service and cannot be the same as any existing user ID in the channel. For example, if there are two users already in the channel and their user IDs are 123 and 456, theuid
cannot be"123"
or"456"
. -
Agora Cloud Recording does not support user IDs in string format (User Accounts). Ensure that every user in the channel has an integer user ID. The string content of the
uid
parameter must also be an integer.
Sample code
For testing purposes, use the following command in the terminal to call the acquire
method.
Start recording
Call the start
method within five minutes of getting a resource ID to join a channel and start recording. You can choose either individual recording or composite recording as the recording mode.
If this method call succeeds, you receive a recording ID (sid) in the HTTP response body. This ID identifies the current recording.
After you obtain the recording ID sid
, you can call the query
, updateLayout
, and stop
methods before the time set (in hours) by resourceExpiredHour
has passed.
Sample code
For testing purposes, use the following command in the terminal to call the start
method.
Query recording status
During a recording session, can call the query
method to query the recording status. You can call this API multiple times.
When you call this method successfully, you receive the current recording status and related information about the recording file in the response body. See Best Practices in Integrating Cloud Recording for details about how to Monitor service status during a recording and Obtain the M3U8 file name.
Sample code
For testing purposes, use the following command in the terminal to call the query
method.
Stop recording
Call the stop
API to end the recording session.
When you call this method successfully, you receive the status of the recording file upload and information about the recording file in the response body.
Sample code
For testing purposes, use the following command in the terminal to call the stop
method.
- If the
uid
parameter in the request body is the same as a user ID in the channel, or if you use a non-integer user ID, the recording fails. For details, see the notes on theuid
parameter in the section Get a cloud recording resource. - When the
start
request returns200
, it only means that the RESTful API request is successful. To ensure that the recording has started successfully and continues normally, callquery
to check the recording status. Errors such as unreasonabletranscodingConfig
parameter settings, incorrect third-party cloud storage information, or incorrect token information cause thequery
method to return404
. See Why do I get a 404 error when I call query after successfully starting a cloud recording? . - Set the
maxIdleTime
parameter based on your business needs. Within the time range set bymaxIdleTime
, the recording continues and billing is generated even if the channel is idle.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
Sample project
Agora provides a Postman collection, which contains sample requests of RESTful API for a cloud recording. You can use the collection to quickly grasp the basic functionalities of the Cloud Recording RESTful APIs. You only need to import the collection to Postman and set your environment variables.
You can also use Postman to generate code snippets written in various programming languages. To do so, select a request, click Code, and select the desired language in GENERATE CODE SNIPPETS.
See also
- To streamline the use of Agora RESTful APIs within your infrastructure, see Quickstart using middleware. The community middleware project provides RESTful APIs for tasks such as token generation and cloud recording management.
- To update the subscription lists during the recording, call
update
. You can call this method multiple times. See Set up subscription lists for details.
-
To set or update the video layout during the recording, call the
updateLayout
method. See Set Video Layout for details. -
Common errors in cloud recording lists common error codes and error messages in the response body.
-
Agora Cloud Recording RESTful API Callback Service lists all the callback events of cloud recording.
-
To learn more about the implementation steps and details of basic functions, you can refer to the following documents:
Next steps
Manage recorded files
After the recording starts, the Agora server splits the recorded content into multiple TS/WebM files and keeps uploading them to the third-party cloud storage until the recording stops. You can refer to Manage Recorded Files to learn about the naming rules, file sizes, and slicing rules of recording files.
Token authentication
To ensure communication security, in a formal production environment, you need to generate tokens on your app server. See Authenticate Your Users with Token.