Use the Content Moderation .NET SDK to retrieve all person group IDs associated with your account.
Prerequisites
Before you begin, make sure that you have:
Installed the required .NET dependencies. For instructions, see Install .NET dependencies.
Use the exact .NET version specified in the installation guide. Using a different version causes subsequent API calls to fail.
Usage notes
This operation queries the IDs of all person groups. For parameter details, see API operation for querying group IDs.
Use the AI Guardrails API endpoints when calling this SDK. For endpoint details, see Endpoint.
Set up authentication
Store your credentials as environment variables to avoid hardcoding sensitive values in your code.
| Environment variable | Description |
|---|---|
ALIBABA_CLOUD_ACCESS_KEY_ID | AccessKey ID of your RAM user |
ALIBABA_CLOUD_ACCESS_KEY_SECRET | AccessKey secret of your RAM user |
The SDK reads these variables at runtime:
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");Never hardcode credentials in your source code or commit them to version control.
Query all person group IDs
The following example initializes a client and calls GetGroups to retrieve all person group IDs. Reuse the client instance across requests to improve moderation performance and avoid repeated connections.
using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;
namespace csharp_sdk_sample
{
class Program
{
static void Main(string[] args)
{
// Initialize the client with credentials from environment variables
DefaultProfile profile = DefaultProfile.GetProfile(
"cn-shanghai",
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
// Reuse this client instance to improve performance and avoid repeated connections
DefaultAcsClient client = new DefaultAcsClient(profile);
GetGroupsRequest request = new GetGroupsRequest();
request.AcceptFormat = FormatType.JSON;
request.ContentType = FormatType.JSON;
request.Method = MethodType.POST;
request.Encoding = "UTF-8";
try
{
GetGroupsResponse response = client.GetAcsResponse(request);
if (response.HttpResponse.Status != 200)
{
Console.WriteLine("Request failed. HTTP status code: {0}", response.HttpResponse.Status);
}
else
{
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
}
}
catch (Exception ex)
{
Console.WriteLine("Request failed: {0}", ex.Message);
}
}
}
}Response structure
A successful response (HTTP 200) returns a JSON object. The response body is printed to the console by System.Text.Encoding.Default.GetString(response.HttpResponse.Content).
For the full response schema and field descriptions, see API operation for querying group IDs.
Common errors
If the request returns a non-200 HTTP status code, check the following:
Authentication errors: Confirm that
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETare set to valid RAM user credentials.Permission errors: Confirm that the RAM user has the required permissions for the Content Moderation service.
Request format errors: Verify the request configuration matches the API reference.
What's next
API operation for querying group IDs — Full parameter reference for the
GetGroupsoperationEndpoint — AI Guardrails API endpoints by region