This page describes how to start cloud recording, query cloud recording status, and stop cloud recording by sending a RESTful API request.
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.
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 .
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.
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.
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.
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.
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, the uid
cannot be "123"
or "456"
.uid
parameter must also be an integer.You can use the command-line tool to send the following command to call the acquire
method.
# Replace <appid> with the App ID of your Agora project
curl --location --request POST 'https://api.agora.io/v1/apps/<appid>/cloud_recording/acquire' \
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
--header 'Authorization: Basic <Authorization>' \
--header 'Content-Type: application/json' \
--data-raw '{
# Replace <YourChannelName> with the name of the channel you need to record
"cname": "<YourChannelName>",
# Replace <YourRecordingUID> with your user ID
"uid": "<YourRecordingUID>",
"clientRequest":{
}
}'
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.
You can use the command-line tool to send the following commands to call the start
method.
# Replace <appid> with the App ID of your Agora project
# Replace <resourceid> with the resource ID obtained through the acquire method
# Replace "<mode>" with "individual" for individual recording or "mix" for composite recording
curl --location --request POST 'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/mode/<mode>/start' \
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
--header 'Authorization: Basic <Authorization>' \
--header 'Content-Type: application/json' \
--data-raw '{
# Replace <YourChannelName> with the name of the channel you need to record.
"cname": "<YourChannelName>",
# Replace <YourRecordingUID> with your user ID that identifies the recording service.
"uid": "<YourRecordingUID>",
"clientRequest": {
# Replace <YourToken> with the temporary token you obtain from the console.
"token": "<YourToken>",
# Set the storageConfig related parameters.
"storageConfig": {
"secretKey": "<YourSecretKey>",
"vendor": 0,
"region": 0,
"bucket": "<YourBucketName>",
"accessKey": "<YourAccessKey>"
},
# Set the recordingConfig related parameters.
"recordingConfig": {
# Which is consistent with the "channelType" of the Agora RTC SDK.
"channelType": 0
}
}
}'
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.
You can use the command-line tool to send the following commands to call the query
method.
# Replace <appid> with the App ID of your Agora project
# Replace <resourceid> with the resource ID obtained through the acquire method
# Replace <sid> with the sid obtained through the start method
# Replace "<mode>" with "individual" for individual recording or "composite" for composite recording
curl --location --request GET 'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/sid/<sid>/mode/<mode>/query' \
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
--header 'Authorization: Basic <Authorization>' \
--header 'Content-Type: application/json' \
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.
You can use the command-line tool to send the following command to call the stop
method.
# Replace <appid> with the App ID of your Agora project
# Replace <resourceid> with the resource ID obtained through the acquire method
# Replace <sid> with the sid obtained through the start method
# Replace "<mode>" with "individual" for individual recording or "mix" for composite recording
curl --location --request POST
'https://api.agora.io/v1/apps/<appid>/cloud_recording/resourceid/<resourceid>/sid/<sid>/mode/<mode>/stop' \
--header 'Content-Type: application/json;charset=utf-8' \
# Replace <Authorization> with the Base64-encoded credential in basic HTTP authentication
--header 'Authorization: Basic <Authorization>' \
--data-raw '{
# Replace <YourRecordingUID> with your user ID that identifies the recording service.
"uid": "<YourRecordingUID>",
# Replace <YourChannelName> with the name of the channel you are recording.
"cname": "<YourChannelName>",
"clientRequest":{
}
}'
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 the uid
parameter in the section Get a cloud recording resource.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 uUnreasonable transcodingConfig
parameter settings, incorrect third-party cloud storage information, or incorrect token information cause the query
method to return 404. See Why do I get a 404 error when I call query after successfully starting a cloud recording? .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.start
method within 5 minutes to start a recording. After the timeout, you need to request a resource ID again.sid
(recording ID), after the time set by resourceExpiredHour
has passed, you are not able to call the query
, updateLayout
, and stop
methods.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.
To ensure communication security, in a formal production environment, you need to generate tokens on your app server. See Authenticate Your Users with Token.
During the recording, you can call update
to update the subscription lists multiple times. See Set up subscription lists for details.
During the recording, you can call the updateLayout
method to set or update the video layout. See Set Video Layout for details.
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**.
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: