API Calling Methods
Usage Instructions
The ZEGOCLOUD server API supports the HTTPS network request protocol, allowing GET or POST methods.
Request Method Overview
Server API requests consist of different components with a fixed request structure:
- Endpoint: The ZEGOCLOUD server endpoint, which varies based on different products and regions.
- Common Parameters: Each request requires a set of common parameters.
- Signature: The signature is also a common parameter that needs to be generated according to the corresponding signature algorithm.
- Request parameters: You need to specify the API through the Action parameter, e.g., Action = CreateDigitalHumanStreamTask; you also need to specify other parameters for the API.
After verifying your request signature, we will return the result. Successful API calls will display return parameters, while failed calls will display corresponding error messages. You can troubleshoot based on the Global Return Codes.
Request Structure
Endpoint
The following is the production endpoint for mainland China. If you need to use the overseas production endpoint, please send an email to aigc@zego.im to activate the overseas plan and obtain the corresponding endpoint.
| Product | Endpoint |
|---|---|
| Digital Human API Service | aigc-digitalhuman-api.zegotech.cn |
Communication Protocol
All ZEGOCLOUD server APIs communicate via HTTPS, providing secure communication services.
Request Method
The ZEGOCLOUD server API supports the following HTTP request methods:
- GET
- POST
- All request parameters (including common and business parameters) are placed in Query using the GET request method. For special complex APIs, business parameters are placed in the Body using the POST request method.
- When using the POST request method to pass parameters, the parameters in the Body can be passed directly in JsonObject format without serializing to String format.
Common Parameters
This section describes the common parameters used when developers call the ZEGOCLOUD server API, including common request parameters and common return parameters.
Common Request Parameters
Common request parameters are required for every API.
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | Uint32 | Yes | AppId, the unique credential assigned by ZEGOCLOUD. Warning Please contact ZEGOCLOUD Technical Support to enable the Digital Human API service and related API permissions. |
| Signature | String | Yes | Signature. For signature generation, please refer to the Signature Mechanism. |
| SignatureNonce | String | Yes | Random number. |
| SignatureVersion | String | Yes | Signature version number, must be set to 2.0. |
| Timestamp | Int64 | Yes | Unix timestamp in seconds. A maximum of 10 minutes' deviation is allowed. |
- Please do not directly copy the examples below for requests.
- The request URL is: https://aigc-digitalhuman-api.zegotech.cn/?Action=xxxxx&common-parameters, where
Action=xxxxxneeds to be replaced with the request URL from the "API Prototype" section of each API document. - Please modify the values of common parameters according to your actual situation.
Request example:
https://aigc-digitalhuman-api.zegotech.cn/?Action=xxx
&AppId=1234567890
&SignatureNonce=15215528852396
&Timestamp=1234567890
&Signature=xxxx
&SignatureVersion=2.0Common Return Parameters
API return results use a unified format with JSON data format.
Every API call, whether successful or not, will return common parameters.
| Parameter | Type | Description |
|---|---|---|
| Code | Number | Return code. |
| Message | String | Operation result description. |
| Data | - | Response data. |
Return example:
{
"Code":0,
"Data":{
"MessageId":"1_1611647493487_29"
},
"Message":"success"
}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. |
