Query person IDs
Use the Content Moderation Go SDK to retrieve all person IDs in a custom group by calling the GetPersons operation.
Prerequisites
Before you begin, ensure that you have:
Installed the Go dependencies using the required Go version. For installation instructions, see Installation.
Use the exact Go version specified in the Installation topic. Mismatched versions cause subsequent operation calls to fail.
Usage notes
Each person must belong to a group. Specifying a
groupIdreturns the IDs of all persons in that group.Use the AI Guardrails API endpoints when calling this SDK. For available endpoints, see Endpoints.
Query person IDs
The GetPersons operation takes a groupId parameter and returns all person IDs registered in that group.
Request parameter
| Parameter | Type | Required | Description |
|---|---|---|---|
groupId | String | Yes | The ID of the custom group to query |
package main
import (
"encoding/json"
"fmt"
"os"
"strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)
func main() {
// Reuse the client instance across calls to improve performance
// and avoid repeated connection overhead.
// Retrieve credentials from environment variables — do not hardcode them.
client, err := green.NewClientWithAccessKey(
"cn-shanghai",
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
)
if err != nil {
fmt.Println(err.Error())
return
}
// groupId: the ID of the custom group to query. Required.
content, _ := json.Marshal(
map[string]interface{}{
"groupId": "<your-group-id>",
},
)
request := green.CreateGetPersonsRequest()
request.SetContent(content)
response, err := client.GetPersons(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("Request failed. HTTP status code: " + strconv.Itoa(response.GetHttpStatus()))
}
fmt.Println(response.GetHttpContentString())
}Replace <your-group-id> with the ID of the group to query.
What's next
For full parameter details and the response structure, see API operation for querying person IDs.