Accessing server APIs
Overview
ZEGOCLOUD server API supports the HTTPS network request protocol and allows GET or POST methods.
Overview of request methods
The server API request consists of different components and has a fixed request structure:
- Access Address: The access address of the ZEGOCLOUD server, which may vary depending on the product and region.
- Common Parameters: Each request must have a series of common parameters.
- Signature: The signature is also a common parameter and needs to be generated according to the corresponding signature algorithm.
- Request Parameters: You need to specify the interface through the Action parameter, such as Action = CreatePlayer; and also specify other parameters of the interface.
After we verify your request based on the signature, we will return the result to you. If the interface call is successful, the return parameters will be displayed. If the call fails, the corresponding error will be displayed. You can analyze and troubleshoot based on the Return codes.
Here is an example of the request structure for the CreatePlayer (Create a cloud player) interface:
https://cloud-player-api.zego.im/?Action=CreatePlayer
&AppId=1234567890
&SignatureNonce=15215528852396
&Timestamp=1234567890
&Signature=7a2c0f11145fb760d607a07b54825013
&SignatureVersion=2.0
&IsTest=falseAmong which:
https: Specifies the request communication protocol.cloud-player-api.zego.im: Specifies the access address of the ZEGOCLOUD server.Action=CreatePlayer: Specifies the API to be called.- Other parameters: Common request parameters that are required for each interface, including AppId, SignatureNonce, Signature, etc. Please refer to Common Request Parameters for details.
Request Structure
Access Address
Developers need to specify the corresponding access address based on the geographical region of their server when sending requests to the ZEGOCLOUD server.
To ensure the quality of your business service access, please prioritize using the domain name of the geographical region where your server is located as the access address when sending requests to the ZEGOCLOUD server.
ZEGOCLOUD supports request access from the following geographical regions:
| Region | API base URL |
|---|---|
| Chinese Mainland (Shanghai) | cloud-player-api-sha.zego.im |
| Hong Kong, Macau and Taiwan (Hong Kong) | cloud-player-api-hkg.zego.im |
| Europe (Frankfurt) | cloud-player-api-fra.zego.im |
| Western United States (California) | cloud-player-api-lax.zego.im |
| Asia-Pacific (Mumbai) | cloud-player-api-bom.zego.im |
| Southeast Asia (Singapore) | cloud-player-api-sgp.zego.im |
| Unified access address (regardless of region) | cloud-player-api.zego.im |
Communication protocol
All ZEGOCLOUD server API interfaces communicate via HTTPS, providing secure communication services.
Request methods
ZEGOCLOUD server API supports the following HTTP request methods:
- GET
- POST
- All request parameters (including common parameters and business parameters) are placed in the Query using the GET request method. For special complex API business parameters, they are placed in the Body using the POST request method.
- When passing parameters using the POST request method, the parameters in the Body can be directly passed in JsonObject format, without the need to serialize them into String format.
Common parameters
This section introduces the common parameters used when developers call the ZEGOCLOUD server API, including common request parameters and common response parameters.
Common request parameters
Common request parameters are required for every interface.
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | Uint32 | Yes | AppId, the unique credential assigned by ZEGOCLOUD. |
| Signature | String | Yes | Signature, please refer to Signing the requests for signature generation. |
| SignatureNonce | String | Yes | Random number. |
| SignatureVersion | String | Yes | Signature version, must be filled in as 2.0. |
| Timestamp | Int64 | Yes | Unix timestamp in seconds. Allow up to 10 minutes of error. |
- Please do not directly copy the following examples for requests.
- The Request endpoint is:
https://cloud-player-api.zego.im/?Action=xxxxx&common parameters, whereAction=xxxxxneeds to be replaced with the Request endpoint in the "Request method and endpoint" section of each API document. - Modify the values of each common parameter according to the actual situation.
Request example:
https://cloud-player-api.zego.im/?Action=xxx
&AppId=1234567890
&Timestamp=1234567890
&Signature=Pc5WB8gokVn0xfeu%2FZV%2BiNM1dgI%3D
&SignatureVersion=2.0
&SignatureNonce=15215528852396
&<Non-common Request Parameters>Common Response Parameters
The API returns results in a unified format, and the data format returned is JSON.
Every time an interface is called, whether successful or not, common parameters will be returned.
| Parameter | Type | Description |
|---|---|---|
| Code | Number | Return code. |
| Message | String | Operation result description. |
| RequestId | String | Request ID. |
| Data | - | Response data. |
Response example:
{
"Code":0,
"Data":{
"MessageId":"1_1611647493487_29"
},
"Message":"success",
"RequestId":"2237080460466033406"
}Signing the requests
To ensure secure API calls, the ZEGOCLOUD server authenticates every API request, which means a request signature must be included in every API request.
A new signature needs to be generated for every API request.
Get the AppId and Server Secret Key
To generate a request signature, you will need to use the AppId and ServerSecret assigned to your project by ZEGOCLOUD. The AppId is used as the identifier of the request sender, and ServerSecret is the secret key to generate the signature string on the request sender side and verify the signature on the ZEGOCLOUD server. To ensure system security, please keep this information strictly confidential.
You can find the AppId and ServerSecret of your project in the ZEGOCLOUD Admin Console.
Generate a signature
Parameters required to generate a signature
| Parameter | Description |
|---|---|
| AppId | Application ID. |
| SignatureNonce | A random string. |
| ServerSecret | Server secret key. |
| Timestamp | Unix timestamp of the current time, in seconds. A maximum error of 10 minutes is allowed. |
| Parameter | Description |
|---|---|
| AppId | Application ID. The AppId in the public parameters. Get it from the ZEGOCLOUD Admin Console. |
| SignatureNonce | A 16-character hexadecimal random string (hex encoding of 8-byte random number). The SignatureNonce in the public parameters. Refer to Signature sample code for how to generate. |
| ServerSecret | Server secret key. Get it from the ZEGOCLOUD Admin Console. |
| Timestamp | Unix timestamp of the current time, in seconds. Refer to Signature sample code for how to generate, with a maximum error of 10 minutes. |
The values of the SignatureNonce and Timestamp parameters used to generate the signature must be consistent with those of the common parameters.
Signature algorithm
Signature = md5(AppId + SignatureNonce + ServerSecret + Timestamp)
Format of the Signature string
The Signature is a hex string of 32 characters in lower case.
Signature sample code
ZEGOCLOUD provides sample code in various programming languages for generating the signature.
import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"fmt"
"log"
"time"
)
// Signature=md5(AppId + SignatureNonce + ServerSecret + Timestamp)
func GenerateSignature(appId uint32, signatureNonce string, serverSecret string, timestamp int64) (Signature string){
data := fmt.Sprintf("%d%s%s%d", appId, signatureNonce, serverSecret, timestamp)
h := md5.New()
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
func main() {
/* Generate a 16-character random hexadecimal string (16 bits) */
nonceByte := make([]byte, 8)
rand.Read(nonceByte)
signatureNonce := hex.EncodeToString(nonceByte)
log.Printf(signatureNonce)
appId := 12345 // Use your appId and serverSecret
serverSecret := "9193cc662a4c0ec135ec71fb57194b38"
timestamp := time.Now().Unix()
/* appId:12345
signatureNonce:4fd24687296dd9f3
serverSecret:9193cc662a4c0ec135ec71fb57194b38
timestamp:1615186943 2021/03/08 15:02:23
signature:43e5cfcca828314675f91b001390566a
*/
log.Printf("signature:%v", GenerateSignature(uint32(appId), signatureNonce, serverSecret, timestamp))
}Signing failures
When a signature verification fails, an error code will be returned.
| return code | description |
|---|---|
| 100000004 | Signature expired. |
| 100000005 | Invalid signature. |
