logo
On this page

Quick start


Introduction

ZEGOCLOUD Analytics Dashboard Server provides multiple Server API interfaces, allowing developers to send requests to the ZEGOCLOUD Server to query user push and pull stream data, regional data, and operation data. Developers can initiate HTTPS network requests and use the GET method to call the Server API to interact with the ZEGOCLOUD Server.

This article takes "how to call a Server API interface" as an example to help developers quickly understand the usage of various Server API interfaces.

Prerequisites

Before calling the Server API interface, please ensure:

  • You have created a project in the ZEGOCLOUD Console and applied for valid AppId and ServerSecret.
  • You have prepared the development environment for debugging the Server API interface.
  • You have prepared your own client and built related business scenarios.

GET Request Example Code

ZEGOCLOUD provides example code in multiple programming languages for developers to refer to based on actual circumstances. For example, to send a GET request to the ZEGOCLOUD Server using the query business usage interface:

package main

import (
	"crypto/md5"
	"crypto/rand"
	"encoding/hex"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"time"
)

//Please modify the AppId to your AppId, and the AppId is uint32
//For example: 1234567890
var appId uint32 = 1234567890

//Please modify the serverSecret to your serverSecret, and the serverSecret is a string
//For example: "abcde1234aaaaaaaabbbbbbb"
var serverSecret = 

func main() {
	queryParams := url.Values{}
	startDate := "20250110"
	endDate := "20250112"
	metrics := "publish_count"
	queryParams.Add("StartDate", startDate)
	queryParams.Add("EndDate", endDate)
    queryParams.Add("Metrics[]", "publish_count")
    queryParams.Add("Metrics[]", "view_count")

	timestamp := time.Now().Unix()
  // Generate a 16-bit hexadecimal random string
	nonce := make([]byte, 8)
	rand.Read(nonce)
	hexNonce := hex.EncodeToString(nonce)
  // Generate a signature
	signature := generateSignature(appId, serverSecret, hexNonce, timestamp)
	authParams := url.Values{}
	authParams.Set("AppId", fmt.Sprintf("%d", appId))
  // The random number in the public parameters must be consistent with the random number generated for the signature
	authParams.Set("SignatureNonce", hexNonce)
	authParams.Set("SignatureVersion", "2.0")
  // The timestamp in the public parameters must be consistent with the timestamp generated for the signature
	authParams.Set("Timestamp", fmt.Sprintf("%d", timestamp))
	authParams.Set("Signature", signature)
	// analytics-api.zego.im represents the request is the Star Map Server API
  // The following example can call the "GetBizUsage" API to query the daily real-time audio-video data statistics within the specified time period
	addr := fmt.Sprintf("https://analytics-api.zego.im/?Action=GetBizUsage&%s&%s", authParams.Encode(), queryParams.Encode())
	rsp, err := http.Get(addr)
	if err != nil {
		fmt.Printf("http.Get err:%+v", err)
		return
	}
	defer rsp.Body.Close()
	body, err := ioutil.ReadAll(rsp.Body)
	if err != nil {
		fmt.Printf("ioutil.ReadAll err:%+v", err)
		return
	}
	fmt.Printf("body:%+v", string(body))
}

// Generate a signature
// Signature=md5(AppId + SignatureNonce + ServerSecret + Timestamp)
func generateSignature(appId uint32, serverSecret, signatureNonce string, timeStamp int64) 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))
}

Usage Process

Developers can quickly initiate a request to the ZEGOCLOUD Server by the following process:

  1. The developer's Server first confirms the request URL address;
  2. Obtain the signature information according to the signature generation rule;
  3. Configure the public request parameters of the developer's Server;
  4. Configure the business parameters of the API;
  5. The developer's Server sends a request to the ZEGOCLOUD Server through the URL address, carrying the request information (including business parameters, signature information, etc.);
  6. The ZEGOCLOUD Server returns the response information.

We take the API interface query business usage as an example, and send a GET request to the ZEGOCLOUD Server for detailed introduction to the usage process.

1 Confirm the URL address

The ZEGOCLOUD Server distinguishes different requests according to different URL addresses. Therefore, the developer's Server accesses the ZEGOCLOUD Server, please get the request URL address from the corresponding interface document first.

The URL address of query business usage is as follows:

https://analytics-api.zego.im/?Action=GetBizUsage

Where:

  • https:Specifies the request communication protocol.
  • analytics-api.zego.im:Specifies the ZEGOCLOUD Server access address, where analytics represents the product used is Star Map, see call method - request structure - access address.
  • Action=GetBizUsage:Specifies the API interface to be called as GetBizUsage.

2 Generate signature information

To ensure the secure call of the API, the ZEGOCLOUD Server will verify the access request of each API. When developers call the API, they need to include the signature Signature information in the request.

Developers can refer to the example code in the call method - signature mechanism for various languages, use the AppId and ServerSecret obtained in this article prerequisites, and generate their own signature information.

3 Configure public request parameters

Before developers call each ZEGOCLOUD Server API, they need to configure the public request parameters of the API.

The public request parameters are the request parameters that each interface needs to use, including AppId, Signature (2 generated signature information), SignatureNonce (random string), Timestamp (timestamp), etc. Please modify according to the actual situation. For details, please refer to call method - public parameters.

https://analytics-api.zego.im/?Action=GetBizUsage&AppId=1234567890&SignatureNonce=15215528852396&Timestamp=1234567890&Signature=Pc5WB8gokVn0xfeu%2FZV%2BiNM1dgI%3D&SignatureVersion=2.0&IsTest=false

After configuring the public parameters, configure the business parameters related to the API to set the desired target operation.

For details, please refer to request parameters.

5 The developer's Server sends a request

After the above configuration is completed, the developer's Server can send a request to the ZEGOCLOUD Server through the URL address.

Request example:

//This request is to get the cumulative push and pull stream from 20250110 to 20250112
https://analytics-api.zego.im/?Action=GetBizUsage
&StartDate=20250110
&EndDate=20250112
&Metrics[]=publish_count
&Metrics[]=play_count
&<public request parameters>

6 The ZEGOCLOUD Server returns the response information

The ZEGOCLOUD Server receives the request information from the developer and returns the response information.

{
    "Code": 0,
    "Data": {
        "Metrics": [
            {
                "Metric": "publish_count",
                "Values": [
                    {
                        "Date": "20250110",
                        "Value": 100
                    },
                    {
                        "Date": "20250111",
                        "Value": 30
                    },
                    {
                        "Date": "20250112",
                        "Value": 40
                    }
                ]
            },
            {
                "Metric": "play_count",
                "Values": [
                    {
                        "Date": "20250110",
                        "Value": 60
                    },
                    {
                        "Date": "20250111",
                        "Value": 20
                    },
                    {
                        "Date": "20250112",
                        "Value": 10
                    }
                ]
            }
        ]
    },
    "Message": "success",
    "RequestId": 1659512998878671000
}

In the returned information fields, if Code is "0", it means the access is successful, and the member list in the room can be viewed; if it is not "0", please refer to global return codes for processing.

Thus, the developer's Server and the ZEGOCLOUD Server have completed one information interaction.

Previous

API Overview

Next

Access Server APIs