REST quickstart
The command-line examples in this article are for demonstration only and should not be used in a production environment. In a production environment, you need to send RESTful API requests through your application server.
Understand the tech
The complete process of implementing a cloud recording is as follows:
1. Get a resource ID
Before starting a cloud recording, you must call the acquire
method to obtain a cloud recording resource. After calling this method successfully, you can get a resource ID in the response body.
2. Start a cloud recording
Call the start
method to join the channel and start a cloud recording. After calling this method successfully, you can get a recording ID from the response body to mark the current recording process.
3. Query the recording status
Call the query
method to check the recording status during the recording.
4. Stop the cloud recording
Call the stop
method to stop the cloud recording.
5. Upload the recording file After the recording is over, the cloud recording service uploads the recording file to the third-party cloud storage you specify.
Prerequisites
- A valid Agora account.
- A valid Agora project with an App ID and a temporary token. For details, see Get Started with Agora.
- A computer with access to the internet. If your network has a firewall, follow the instructions in Firewall Requirements.
- Ensure that a third-party cloud storage service has been enabled. The currently supported third-party cloud storage service providers are as follows:
- Ensure that you have joined the RTC channel and have users in the channel and are streaming.
Project setup
Enable the cloud recording service before using Agora Cloud Recording for the first time.
-
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.
-
Click Enable Cloud Recording.
-
Click Apply.
Now, you can use Agora Cloud Recording and see the usage statistics in the Usage page.
Implement the cloud recording
The following figure shows the API call sequence of a cloud recording:
Querying the recording status (query
), updating the subscription list (update
), and updating the video layout (updateLayout
) are optional and can be called multiple times, but they must be called during the recording process, that is, after the recording starts and before the recording ends.
Pass the basic HTTP authentication
The RESTful APIs require basic HTTP authentication. You need to set the Authorization
parameter in every HTTP request header. For how to get the value for Authorization, see basic HTTP authentication.
acquire: Get a resource ID
Call the acquire
method to request a resource ID for cloud recording.
After calling this method successfully, you can get a resource ID in the response body. The resource ID is valid for five minutes, so you need to start recording with this resource ID within five minutes. One resource ID can only be used for one 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, that is, 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
You can use the command-line tool to send the following command to call the acquire
method.
Start recording
Call the start
method within five minutes after getting the resource ID to join a channel and start the recording. You can choose either individual recording or composite recording as the recording mode.
If this method call succeeds, you get a recording ID (sid) from the HTTP response body. This ID is the unique identification of the current recording.
Sample code
You can use the command-line tool to send the following commands to call the start
method.
query: Query recording status
During the recording, you can call the query
method to query the recording status multiple times.
After calling this method successfully, you can get the current recording status and related information about the recording file from 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
You can use the command-line tool to send the following commands to call the query
method.
stop: Stop recording
Call the stop
the recording.
After calling this method successfully, you can get the status of the recording file upload and information about the recording file from the response body.
Sample code
You can use the command-line tool to send the following command to call the stop
method.
Considerations
Parameter settings
- If the
uid
parameter in the request body is the same as the user ID in the channel, or if a non-integer user ID is used, the recording fails. For details, see the notes on theuid
parameter in the section Get a cloud recording resource. - When the
start
request returns 200, it means only that the RESTful API request is successful. To ensure that the recording starts successfully and goes on normally, you also need to call query to query the recording status. Errors such as uUnreasonabletranscodingConfig
parameter settings, incorrect third-party cloud storage information, or incorrect token information cause thequery
method to return 404. See Why do I get a 404 error when I call query after successfully starting a cloud recording? . - Set
maxIdleTime
reasonably according to your actual business needs. Within the time range set bymaxIdleTime
, even if the channel is idle, the recording continues and billing is generated.
API call
- After obtaining the resource ID, you must call the
start
method within 5 minutes to start a recording. After the timeout, you need to request a resource ID again. - After obtaining the
sid
(recording ID), after the time set byresourceExpiredHour
has passed, you are not able to call thequery
,updateLayout
, andstop
methods.
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.
See also
Update subscription lists
During the recording, you can call update
to update the subscription lists multiple times. See Set up subscription lists for details.
Update video layout
During the recording, you can call the updateLayout
method to set or update the video layout. See Set Video Layout for details.
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.
Reference documents
-
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: