How to call RESTful API
This page explains the structure of the channel management RESTful API and how to call it correctly.
Prerequisites
Before calling the API, make sure you have the following:
- An Agora app ID
- Customer ID
- Customer key
Request URL
Following is a sample request URL:
https
: The communication protocol. Agora uses HTTPS.api.agora.io
: The domain name of the Agora server.dev/v1/kicking-rule
: The resource path, including the API version and the resource name.
The above example is for reference only. Refer to the documentation of the API you want to call, select the method (GET
, POST
, PUT
, PATCH
, DELETE
) in the code source file or debug application, and then configure the actual request URL according to your needs. The request URL is case-sensitive.
Request structure
A request consists of two parts: The request header and the request body.
The following example shows how to create a privilege banning rule by sending a POST
request containing the app ID, channel name, user ID, user IP, ban duration, and the privilege list to the specified API address:
Request header
The request header contains the following information needed to process the request:
Accept
: Tells the server what types of responses the client can handle, such asapplication/json
.Authorization
: The Agora RESTful API requires HTTP authentication. Every time you send an HTTP request, fill in theAuthorization
field in the request header. See RESTful authentication for details.Content-Type
: Specifies the type of the request body, such asapplication/json
.
Request body (optional)
The request body contains the information to be sent to the server. For example, to create a new rule to ban user privileges, include the relevant information, such as the app ID, channel name, user ID, user IP, ban duration, and the banned privileges. The request body is case-sensitive.
Response
After you send the request, the Agora server sends a response that includes a response status code and a response body. The channel management RESTful API does not have a response header.
Response status code
The HTTP response status code can be one of the following:
200
: The request is successful.- Other than
200
: Refer to Response status codes to troubleshoot the problem.
Response body
The response body contains the information returned by the server. For example, the response body of creating a banning rule includes the request status and the rule ID.
The following is a response example for creating a banning rule:
Error handling
If you encounter a problem, use developer tools to view the request and response, and troubleshoot based on the response status code. If the problem persists, contact technical support.