Share via


BlocklistClient.AddOrUpdateBlocklistItemsAsync Method

Definition

Overloads

AddOrUpdateBlocklistItemsAsync(String, AddOrUpdateTextBlocklistItemsOptions, CancellationToken)

Add or update BlocklistItems To Text Blocklist.

AddOrUpdateBlocklistItemsAsync(String, RequestContent, RequestContext)

[Protocol Method] Add or update BlocklistItems To Text Blocklist

AddOrUpdateBlocklistItemsAsync(String, AddOrUpdateTextBlocklistItemsOptions, CancellationToken)

Source:
BlocklistClient.cs

Add or update BlocklistItems To Text Blocklist.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsResult>> AddOrUpdateBlocklistItemsAsync (string name, Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsOptions options, System.Threading.CancellationToken cancellationToken = default);
abstract member AddOrUpdateBlocklistItemsAsync : string * Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsResult>>
override this.AddOrUpdateBlocklistItemsAsync : string * Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AddOrUpdateTextBlocklistItemsResult>>
Public Overridable Function AddOrUpdateBlocklistItemsAsync (name As String, options As AddOrUpdateTextBlocklistItemsOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AddOrUpdateTextBlocklistItemsResult))

Parameters

name
String

Text blocklist name.

options
AddOrUpdateTextBlocklistItemsOptions

Options for adding or updating blocklist items.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

name or options is null.

name is an empty string, and was expected to be non-empty.

Examples

This sample shows how to call AddOrUpdateBlocklistItemsAsync.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
BlocklistClient client = new BlocklistClient(endpoint, credential);

AddOrUpdateTextBlocklistItemsOptions options = new AddOrUpdateTextBlocklistItemsOptions(new TextBlocklistItem[]
{
    new TextBlocklistItem("<text>")
});
Response<AddOrUpdateTextBlocklistItemsResult> response = await client.AddOrUpdateBlocklistItemsAsync("<Name>", options);

This sample shows how to call AddOrUpdateBlocklistItemsAsync with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
BlocklistClient client = new BlocklistClient(endpoint, credential);

AddOrUpdateTextBlocklistItemsOptions options = new AddOrUpdateTextBlocklistItemsOptions(new TextBlocklistItem[]
{
    new TextBlocklistItem("<text>")
    {
        Description = "<description>",
    }
});
Response<AddOrUpdateTextBlocklistItemsResult> response = await client.AddOrUpdateBlocklistItemsAsync("<Name>", options);

Remarks

Add or update blocklistItems to a text blocklist. You can add or update at most 100 blocklistItems in one request.

Applies to

AddOrUpdateBlocklistItemsAsync(String, RequestContent, RequestContext)

Source:
BlocklistClient.cs

[Protocol Method] Add or update BlocklistItems To Text Blocklist

public virtual System.Threading.Tasks.Task<Azure.Response> AddOrUpdateBlocklistItemsAsync (string name, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member AddOrUpdateBlocklistItemsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.AddOrUpdateBlocklistItemsAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function AddOrUpdateBlocklistItemsAsync (name As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

name
String

Text blocklist name.

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

name or content is null.

name is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call AddOrUpdateBlocklistItemsAsync and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
BlocklistClient client = new BlocklistClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    blocklistItems = new object[]
    {
        new
        {
            text = "<text>",
        }
    },
});
Response response = await client.AddOrUpdateBlocklistItemsAsync("<Name>", content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("blocklistItems")[0].GetProperty("blocklistItemId").ToString());
Console.WriteLine(result.GetProperty("blocklistItems")[0].GetProperty("text").ToString());

This sample shows how to call AddOrUpdateBlocklistItemsAsync with all parameters and request content and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
BlocklistClient client = new BlocklistClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    blocklistItems = new object[]
    {
        new
        {
            description = "<description>",
            text = "<text>",
        }
    },
});
Response response = await client.AddOrUpdateBlocklistItemsAsync("<Name>", content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("blocklistItems")[0].GetProperty("blocklistItemId").ToString());
Console.WriteLine(result.GetProperty("blocklistItems")[0].GetProperty("description").ToString());
Console.WriteLine(result.GetProperty("blocklistItems")[0].GetProperty("text").ToString());

Applies to