# 删除用户画像

> 清除用户画像的个人数据并取消其计划发送的邮件。可用于履行数据删除权请求。
>
> 通过 `external_profile_id`、`customer_user_id` 和 `email` 的任意组合来标识用户画像——Adapty Mail 的解析方式与保存时相同。
>
> 删除操作不可撤销。之后使用相同标识符发起的 [保存用户画像](#operation/saveProfile) 请求不会重新创建该用户画像。
>
> 通过 `external_profile_id` 或 `customer_user_id` 重复删除操作时，请求会再次成功但不会产生任何变化。若仅通过 `email` 重复删除，则会返回 `404`：因为删除操作会清除已存储的邮件地址，导致无法再通过邮件进行匹配。

## OpenAPI

```yaml
/api-specs/adapty-mail-api.yaml post /api/v1/profile/delete/
openapi: 3.1.0
info:
  title: Adapty Mail API
  version: 1.0.0
  description: |
    Adapty Mail API 允许您直接从服务器将用户画像和交易事件发送到 Adapty Mail，
    无需通过 Adapty SDK 路由数据。

    使用场景：

    - 当您在 Adapty Mail 中尚无用户群时，添加订阅者。
    - 复用其他应用中的订阅者群。
    - 以您的后端作为数据源，以服务端对服务端的方式向 Adapty Mail 提供数据。

    包含电子邮件地址的用户画像足以触发**从未购买**流程。其他所有流程
    （续订已取消、账单问题、已过期、已退款）均由购买历史驱动，因此这些
    用户画像还需要提供交易事件，才能进入正确的流程。

    如需分步操作指南，请参阅 [通过 Adapty Mail API 发送邮件和交易数据](/docs/mail-send-data-via-api)。
servers:
  - url: https://api-mail.adapty.io
    description: 生产服务器
paths:
  /api/v1/profile/delete/:
    post:
      summary: 删除用户画像
      description: |
        清除用户画像的个人数据并取消其计划发送的邮件。可用于履行数据删除权请求。

        通过 `external_profile_id`、`customer_user_id` 和 `email` 的任意组合来标识用户画像——Adapty Mail 的解析方式与保存时相同。

        删除操作不可撤销。之后使用相同标识符发起的 [保存用户画像](#operation/saveProfile) 请求不会重新创建该用户画像。

        通过 `external_profile_id` 或 `customer_user_id` 重复删除操作时，请求会再次成功但不会产生任何变化。若仅通过 `email` 重复删除，则会返回 `404`：因为删除操作会清除已存储的邮件地址，导致无法再通过邮件进行匹配。
      operationId: deleteProfile
      security:
        - apikeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ProfileDeleteDTO"
            examples:
              byExternalProfileId:
                summary: 通过保存用户画像时提供的标识符进行删除
                value:
                  external_profile_id: user_12345
              byEmail:
                summary: 通过邮件地址进行删除
                value:
                  email: jane@example.com
      responses:
        "204":
          description: 用户画像已删除。响应无正文内容。
        "400":
          description: 未提供任何标识符。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Errors"
              examples:
                default:
                  value:
                    errors:
                      - message: At least one of external_profile_id, customer_user_id or email must be provided
                        error_code: missing_identifier
                        status_code: 400
                        field_name: null
        "403":
          description: API 密钥缺失或无效。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Errors"
              examples:
                default:
                  value:
                    errors:
                      - message: Secret key doesn't exist
                        error_code: secret_key_does_not_exist_error
                        status_code: 403
                        field_name: null
        "404":
          description: 未找到与所提供标识符匹配的用户画像。
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Errors"
              examples:
                default:
                  value:
                    errors:
                      - message: Profile not found
                        error_code: profile_not_found_error
                        status_code: 404
                        field_name: null
components:
  schemas:
    ProfileDeleteDTO:
      type: object
      description: |
        要删除的用户画像标识符。请至少提供 `external_profile_id`、
        `customer_user_id` 或 `email` 之一。
      anyOf:
        - required:
            - external_profile_id
        - required:
            - customer_user_id
        - required:
            - email
      properties:
        external_profile_id:
          type: string
          description: 保存用户画像时您所发送的标识符。
        customer_user_id:
          type: string
          description: 用户在您自有系统中的标识符。
        email:
          type: string
          format: email
          description: 用户画像中的电子邮件地址。
    Errors:
      type: object
      description: 标准错误响应。每次失败都会返回一个包含此结构的 4XX 状态。
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
                description: 人类可读的错误描述。
              error_code:
                type: string
                description: 机器可读的错误标识符。
              status_code:
                type: integer
                description: 此错误的 HTTP 状态码。
              field_name:
                type: string
                description: 导致错误的请求字段，如果错误与字段无关则为 `null`。
  securitySchemes:
    apikeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: |
        使用您的 Adapty Mail 密钥对每个请求进行身份验证，将其作为 **Authorization** 请求头发送，
        值格式为 `Bearer {your_secret_api_key}`，例如 `Bearer secret_live_...`。

        在 Adapty Mail 的**设置**中找到该密钥。该密钥与项目绑定——它标识数据所属的项目，
        因此用户画像和交易相关接口无需传入项目 ID。
```
