> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# 批量清除生物特征模板 API：按 ID 或筛选条件删除

> Didit 提供 POST /v3/biometric-templates/delete/，可按 ID 列表或筛选条件清除留存的人脸生物特征模板。每个模板的操作均幂等。

一次调用即可清除多个模板。可以提供明确的 ID 列表，或提供 `delete_all: true`，并可选择使用与 [列出生物特征模板](https://docs.didit.me/zh/management-api/biometric-templates/list.md) 相同的过滤条件进一步缩小范围。

## 请求体

| 字段 | 类型 | 说明 |
| - | - | - |
| `template_uuids` | UUID\[] | 要清除的模板。除非 `delete_all` 为 `true`，否则为必填项。已被清除的 ID 会被报告为 `already_purged`。 |
| `delete_all` | boolean | 为 `true` 时，清除符合以下过滤条件的所有模板（未提供过滤条件时，清除应用中的全部模板）。`template_uuids` 将被忽略。 |
| `vendor_data` | string | 仅与 `delete_all` 一起使用：对所属用户的 `vendor_data` 进行不区分大小写的子串匹配 |
| `vendor_user_uuid` | UUID | 仅与 `delete_all` 一起使用：对所属用户进行精确匹配 |
| `status` | enum | 仅与 `delete_all` 一起使用：`pending`、`active`、`expired`、`held_out_of_use`、`purge_pending`、`purge_failed` |
| `source_type` | enum | 仅与 `delete_all` 一起使用：`session_delete`、`automatic_retention`、`backfill` |
| `retained_from`、`retained_to` | datetime | 仅与 `delete_all` 一起使用：保留日期范围 |

> [!WARNING]
>
> 不带过滤条件的 `delete_all: true` 会清除应用中的所有生物特征模板，且无法撤销。请先使用相同的过滤条件运行 [统计生物特征模板](https://docs.didit.me/zh/management-api/biometric-templates/count.md)，确认将被清除的内容。

## 示例

> [tab] 按 ID
>
> ```bash theme={null}
> curl -X POST https://verification.didit.me/v3/biometric-templates/delete/ \
>   -H "x-api-key: YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{"template_uuids": ["9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d"]}'
> ```

> [tab] 某个用户的所有模板
>
> ```bash theme={null}
> curl -X POST https://verification.didit.me/v3/biometric-templates/delete/ \
>   -H "x-api-key: YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{"delete_all": true, "vendor_user_uuid": "2f7c1a9e-8b4d-4c6a-9e1f-3d5b7a9c1e2f"}'
> ```

> [tab] 应用中的所有模板
>
> ```bash theme={null}
> curl -X POST https://verification.didit.me/v3/biometric-templates/delete/ \
>   -H "x-api-key: YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{"delete_all": true}'
> ```

```json theme={null}
{
  "results": [
    { "uuid": "9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "outcome": "purged" },
    { "uuid": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "outcome": "already_purged" }
  ]
}
```

模板逐个清除。每个结果都会报告 `purged` 或 `already_purged`。如果某个生物特征存储不可用，调用会在第一个失败的模板处返回 `503`。同一请求中此前已清除的模板保持清除状态，失败的模板会转为 `purge_failed`（已排除在匹配之外）。重复该请求即可完成剩余的清除工作。

## 错误

| 状态 | 触发条件 | 响应体 |
| - | - | - |
| `400` | 既未提供 `template_uuids`，也未提供 `delete_all: true` | `{"template_uuids": ["This field is required unless delete_all is true."]}` |
| `400` | 过滤值无效，或 `retained_to` 早于 `retained_from` | 按字段返回的校验错误 |
| `403` | 使用了控制台用户令牌，或该 API 密钥无权执行此操作 | `{"detail": "You do not have permission to perform this action."}` |
| `503` | 生物特征存储不可用；请重复该请求 | `{"detail": "The biometric-template operation could not finish because an external store is unavailable. The operation is retryable."}` |


## OpenAPI

````yaml zh/openapi-25.json POST /v3/biometric-templates/delete/
openapi: 3.0.0
info:
  version: 3.0.0
  title: Didit Verification API
  description: 身份证件验证 API。使用 x-api-key 请求头进行身份验证。
servers:
  - url: https://verification.didit.me
security: []
tags: []
paths:
  /v3/biometric-templates/delete/:
    post:
      tags:
        - Biometric Templates
      summary: 批量清除保留的生物特征模板
      description: >-
        已选择启用的应用在会话被删除时（参见 `DELETE
        /v3/session/{sessionId}/delete/`），会保留一个单独管理的、不含图像的人脸生物特征模板并锚定至用户。模板是具有有限有效期（由
        `expires_at` 指定）的生物识别数据；它们绝不包含图像、会话数据或身份字段，并在用户删除、隐私擦除、过期或显式清除时被清除。这些
        endpoint 仅接受应用 API 密钥（`x-api-key`）；Business Console 用户 token 将被拒绝并返回
        `403`。


        可通过单次调用清除多个模板：指定 id 列表，或使用 `delete_all: true`（可选使用与列表 endpoint
        相同的过滤器缩小范围）。模板会被逐一清除，每个结果会报告 `purged` 或
        `already_purged`。如果生物识别存储库不可用，调用将在遇到第一个失败的模板时返回
        `503`：请求中先前已清除的模板保持已清除状态，失败的模板状态变为 `purge_failed`（已排除在比对之外），重试该请求即可完成操作。


        **不带过滤器的 `delete_all: true` 会清除应用中的所有生物特征模板，且无法撤销。** 请先使用相同的过滤器调用计数
        endpoint。
      operationId: bulk_purge_biometric_templates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                template_uuids:
                  type: array
                  items:
                    type: string
                    format: uuid
                  minItems: 1
                  description: >-
                    要清理的模板。除非 `delete_all` 为 `true`，否则此项必填。已经清理过的 ID 将报告为
                    `already_purged`。
                delete_all:
                  type: boolean
                  default: false
                  description: >-
                    为 `true` 时，清除与以下过滤器匹配的每个模板（未提供过滤器时为应用的所有模板）。`template_uuids`
                    将被忽略。不可逆。
                vendor_data:
                  type: string
                  description: 仅适用于 `delete_all`：对所属用户的 `vendor_data` 进行不区分大小写的子字符串匹配。
                vendor_user_uuid:
                  type: string
                  format: uuid
                  description: 仅适用于 `delete_all`：与所属用户精确匹配。
                status:
                  type: string
                  enum:
                    - pending
                    - active
                    - expired
                    - held_out_of_use
                    - purge_pending
                    - purge_failed
                  description: 仅与 `delete_all` 一起使用。
                source_type:
                  type: string
                  enum:
                    - session_delete
                    - automatic_retention
                    - backfill
                  description: 仅与 `delete_all` 一起使用。
                retained_from:
                  type: string
                  format: date-time
                  description: 仅与 `delete_all` 一起使用。
                retained_to:
                  type: string
                  format: date-time
                  description: 仅与 `delete_all` 一起使用。不得早于 `retained_from`。
            examples:
              By id:
                value:
                  template_uuids:
                    - 9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b
                    - 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d
              Every template of one User:
                value:
                  delete_all: true
                  vendor_user_uuid: 2f7c1a9e-8b4d-4c6a-9e1f-3d5b7a9c1e2f
              Every template in the application:
                value:
                  delete_all: true
      responses:
        '200':
          description: 按模板划分的清理结果。
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        uuid:
                          type: string
                          format: uuid
                        outcome:
                          type: string
                          enum:
                            - purged
                            - already_purged
              examples:
                Mixed:
                  value:
                    results:
                      - uuid: 9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b
                        outcome: purged
                      - uuid: 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                        outcome: already_purged
        '400':
          description: 验证错误 — 未清除任何内容。
          content:
            application/json:
              examples:
                Missing selector:
                  value:
                    template_uuids:
                      - This field is required unless delete_all is true.
                Bad range:
                  value:
                    retained_to:
                      - Must be on or after retained_from.
        '403':
          description: Console 用户 token，或该 API 密钥不被允许。这些 endpoint 仅接受应用 API 密钥。
          content:
            application/json:
              examples:
                Forbidden:
                  value:
                    detail: You do not have permission to perform this action.
        '503':
          description: 在保留或清除生物特征模板时，生物特征存储库不可用。未删除任何内容；请重试相同的请求。重试具有幂等性，并最终收敛至单个模板。
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
              examples:
                Retryable:
                  value:
                    detail: >-
                      The biometric-template operation could not finish because
                      an external store is unavailable. The operation is
                      retryable.
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: curl
          label: curl
          source: >-
            curl -X POST
            https://verification.didit.me/v3/biometric-templates/delete/ \
              -H 'x-api-key: YOUR_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{"delete_all": true, "vendor_user_uuid": "2f7c1a9e-8b4d-4c6a-9e1f-3d5b7a9c1e2f"}'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.biometric_templates.batch_delete(
                template_uuids=["9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d"],
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: |-
            import Didit from "@didit-protocol/sdk-node";

            // Reads DIDIT_API_KEY.
            const didit = new Didit();

            const result = await didit.biometricTemplates.batchDelete({
              template_uuids: ["9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d"],
            });
            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.BiometricTemplates.BatchDelete(ctx, didit.BiometricTemplatesBatchDeleteParams{\n\tTemplateUUIDs: didit.Some([]string{\"9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b\", \"1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d\"}),\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import java.util.List;

            import me.didit.Didit;

            import me.didit.types.BiometricTemplatesBatchDeleteParams;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.biometricTemplates().batchDelete(BiometricTemplatesBatchDeleteParams.builder()
                    .templateUuids(List.of("9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d"))
                    .build());
            System.out.println(result);
        - lang: php
          label: PHP
          source: |-
            <?php

            require 'vendor/autoload.php';

            use Didit\DiditClient;

            // Reads DIDIT_API_KEY.
            $didit = new DiditClient();

            $result = $didit->biometricTemplates->batchDelete([
                'template_uuids' => ['9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b', '1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d'],
            ]);
            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: >-
            require "didit"


            # Reads DIDIT_API_KEY.

            didit = Didit::Client.new


            result = didit.biometric_templates.batch_delete(template_uuids:
            ["9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b",
            "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d"])

            puts result.to_h
        - lang: csharp
          label: .NET
          source: >-
            using System;

            using System.Text.Json;

            using Didit;


            // Reads DIDIT_API_KEY.

            using var client = new DiditClient();


            var result = await client.BiometricTemplates.BatchDeleteAsync(new
            BiometricTemplatesBatchDeleteParams

            {
                TemplateUuids = new string[] { "9d2f4b6e-1c3a-4e8f-b7d5-0a1c2e3f4a5b", "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d" },
            });

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        您的应用 API 密钥，可在 Business Console 的“开发者 -> API
        密钥”中获取。主密钥拥有完整访问权限。指定名称的密钥可设置作用域：针对每个资源设为无权限、只读或读写，限定于特定工作流或已通过的会话、限定于
        IP 地址列表，以及设置到期日期。401 表示密钥错误、已撤销或已过期；403 表示未发送密钥、密钥无权访问该资源或操作，或请求来自其 IP
        列表之外的地址；在会话路由上返回 404 表示该会话不在该密钥允许的工作流或状态范围内。没有媒体访问权限的密钥获取到的图片、视频和 PDF
        URL 将为 null；没有会话写入权限的密钥获取到的会话链接和 token 将为 null。请参阅
        https://docs.didit.me/console/api-keys。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.