Add a person

更新时间:
复制 MD 格式

Use the .NET SDK to add a person to one or more custom groups in Content Moderation.

Prerequisites

Before you begin, make sure you have:

  • Installed the .NET dependencies. See Install .NET dependencies for instructions. Use the exact .NET version specified in the installation guide — using a different version causes subsequent API calls to fail.

  • Identified the custom group IDs to assign the person to. You must specify the group to which the person will join.

Usage notes

.NET SDK implementation

Parameters

The request body accepts the following parameters:

ParameterRequiredDescription
personIdYesThe ID of the custom person
groupIdsYesA list of custom group IDs to assign the person to
nameNoThe name of the person
noteNoRemarks

Code example

The following example adds a person and assigns them to two custom groups. Replace the placeholder values with your actual IDs before running.

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)
        {
            // Load credentials from environment variables.
            // ALIBABA_CLOUD_ACCESS_KEY_ID: AccessKey ID of your RAM user
            // ALIBABA_CLOUD_ACCESS_KEY_SECRET: AccessKey secret of your RAM user
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                    Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));

            // Reuse the client instance across calls to improve performance
            // and avoid repeated connection overhead.
            DefaultAcsClient client = new DefaultAcsClient(profile);

            AddPersonRequest request = new AddPersonRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("personId", "<person-id>");
            httpBody.Add("groupIds", new List<string> { "<group-id-1>", "<group-id-2>" });
            httpBody.Add("name", "<name>");               // optional
            httpBody.Add("note", "<remarks>");            // optional

            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);

            try
            {
                AddPersonResponse response = client.GetAcsResponse(request);

                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("Request failed. HTTP status: {0}", response.HttpResponse.Status);
                }

                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Request failed: {0}", ex.Message);
            }
        }
    }
}

Replace the following placeholders with actual values:

PlaceholderDescription
<person-id>The ID of the custom person to add
<group-id-1>, <group-id-2>The IDs of the custom groups to assign the person to
<name>The name of the person (optional)
<remarks>Any remarks about the person (optional)
Note

Note: A successful response returns HTTP status 200. Any other status code indicates a failed request — check the response body for error details.

What's next