# Tạo hồ sơ người dùng

> Tạo người dùng cuối mới trong ứng dụng của bạn trong Adapty.

## OpenAPI

```yaml
/api-specs/adapty-api.yaml post /api/v2/server-side-api/profile/
openapi: 3.1.0
info:
  title: Adapty server-side API
  version: 1.0.0
servers:
  - url: https://api.adapty.io
    description: Máy chủ sản xuất
paths:
  /api/v2/server-side-api/profile/:
    post:
      summary: Tạo hồ sơ người dùng
      description: Tạo người dùng cuối mới trong ứng dụng của bạn trong Adapty.
      operationId: createProfile
      tags:
        - Profile
      security:
        - apikeyAuth: []
      parameters:
        - name: adapty-customer-user-id
          in: header
          required: false
          schema:
            type: string
          description: ID duy nhất của khách hàng trong hệ thống của bạn. Cần cung cấp `adapty-customer-user-id` hoặc `adapty-profile-id`.
        - name: adapty-profile-id
          in: header
          required: false
          schema:
            type: string
          description: ID duy nhất của hồ sơ người dùng trong hệ thống của bạn. Lựa chọn tốt nhất khi làm việc với hồ sơ ẩn danh. Cần cung cấp `adapty-customer-user-id` hoặc `adapty-profile-id`.
        - name: adapty-platform
          in: header
          required: false
          schema:
            type: string
          description: Nền tảng của thiết bị nơi người dùng cài đặt ứng dụng của bạn
      responses:
        "200":
          description: Hồ sơ người dùng được tạo thành công
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ProfileResponse"
              example:
                data:
                  app_id: 14c3d623-2f3a-455a-aa86-ef83dff6913b
                  profile_id: 3286abd3-48b0-4e9c-a5f6-ac0a006804a6
                  customer_user_id: jane.doe@example.com
                  total_revenue_usd: 0
                  segment_hash: 8f45947bad31ab0c
                  timestamp: 1736425645861
                  custom_attributes:
                    - key: favourite_sport
                      value: yoga
                  access_levels: []
                  subscriptions: []
                  non_subscriptions: []
        "401":
          description: Không được phép
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                errors:
                  - source: non_field_errors
                    errors:
                      - Authentication credentials were not provided.
                error_code: not_authenticated
                status_code: 401
        "500":
          description: Lỗi máy chủ nội bộ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ProfileRequest"
            example:
              first_name: Jane
              last_name: Doe
              gender: f
              email: jane.doe@example.com
              phone_number: "+1234567890"
              birthday: "2000-12-31"
              ip_country: FR
              store_country: US
              store: app_store
              analytics_disabled: true
              custom_attributes:
                - key: favourite_sport
                  value: yoga
              installation_meta:
                device_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
                device: string
                locale: en
                os: string
                platform: iOS
                timezone: Europe/Rome
                user_agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1
                idfa: EA7583CD-A667-48BC-B806-42ECB2B48333
                idfv: E9D48DA5-3930-4B41-8521-D953AECD2F33
                advertising_id: ""
                android_id: ""
                android_app_set_id: ""
components:
  schemas:
    ProfileResponse:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Profile"
      required:
        - data
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              source:
                type: string
                nullable: true
                description: Nguồn gốc lỗi
              errors:
                type: array
                items:
                  type: string
                description: Mảng thông báo lỗi
        error_code:
          type: string
          description: Tên lỗi rút gọn
        status_code:
          type: integer
          description: Mã trạng thái HTTP
      required:
        - errors
        - error_code
        - status_code
    ProfileRequest:
      type: object
      properties:
        first_name:
          type: string
          nullable: true
          description: Tên của người dùng cuối
        last_name:
          type: string
          nullable: true
          description: Họ của người dùng cuối
        gender:
          type: string
          nullable: true
          enum:
            - f
            - m
            - o
          description: Giới tính của người dùng cuối
        email:
          type: string
          nullable: true
          format: email
          description: Email của người dùng cuối
        phone_number:
          type: string
          nullable: true
          description: Số điện thoại của người dùng cuối
        birthday:
          type: string
          format: date
          nullable: true
          description: Ngày sinh của người dùng cuối
        ip_country:
          type: string
          nullable: true
          description: Quốc gia của người dùng cuối theo định dạng ISO 3166-2
        ip_v4_address:
          type: string
          nullable: true
          description: Địa chỉ IPv4 của người dùng cuối
        store_country:
          type: string
          nullable: true
          description: Quốc gia của cửa hàng ứng dụng của người dùng cuối
        store:
          type: string
          nullable: true
          enum:
            - app_store
            - play_store
            - stripe
            - adapty
            - paddle
          description: Nền tảng người dùng sử dụng để thực hiện giao dịch mua trong ứng dụng của bạn
        store_account_token:
          type: string
          format: uuid
          nullable: true
          description: Token tài khoản cửa hàng
        att_status:
          type: integer
          nullable: true
          enum:
            - 0
            - 1
            - 2
            - 3
          description: Trạng thái Apple App Tracking Transparency (0=chưa xác định, 1=bị hạn chế, 2=bị từ chối, 3=được ủy quyền)
        analytics_disabled:
          type: boolean
          nullable: true
          description: Tùy chọn hủy tham gia phân tích bên ngoài
        custom_attributes:
          type: array
          items:
            $ref: "#/components/schemas/CustomAttribute"
          description: Cho phép đặt tối đa 30 thuộc tính tùy chỉnh cho hồ sơ người dùng
        installation_meta:
          $ref: "#/components/schemas/InstallationMeta"
      required:
        - installation_meta
      example:
        first_name: Jane
        last_name: Doe
        gender: f
        email: jane.doe@example.com
        phone_number: "+1234567890"
        birthday: "2000-12-31"
        ip_country: FR
        ip_v4_address: 192.168.1.1
        store_country: US
        store: app_store
        store_account_token: 3fa85f64-5717-4562-b3fc-2c963f66afa6
        att_status: 3
        analytics_disabled: true
        custom_attributes:
          - key: favourite_sport
            value: yoga
        installation_meta:
          device_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
          device: iPhone 15 Pro
          locale: en
          os: iOS 17.1
          platform: iOS
          timezone: Europe/Rome
          user_agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1
          app_build: 1.0.0
          app_version: 1.0.0
          adapty_sdk_version: 2.0.0
          idfa: EA7583CD-A667-48BC-B806-42ECB2B48333
          idfv: E9D48DA5-3930-4B41-8521-D953AECD2F33
          advertising_id: ""
          android_id: ""
          android_app_set_id: ""
    Profile:
      type: object
      properties:
        app_id:
          type: string
          format: uuid
          description: ID nội bộ của ứng dụng của bạn
        profile_id:
          type: string
          format: uuid
          description: ID hồ sơ người dùng Adapty
        customer_user_id:
          type: string
          nullable: true
          description: ID người dùng của bạn trong hệ thống của bạn
        total_revenue_usd:
          type: number
          format: float
          description: Giá trị float biểu thị tổng doanh thu tính bằng USD kiếm được trong hồ sơ người dùng
        segment_hash:
          type: string
          description: Tham số nội bộ
        timestamp:
          type: integer
          format: int64
          description: Thời gian phản hồi tính bằng mili giây, cần để giải quyết điều kiện tranh chấp
        custom_attributes:
          type: array
          items:
            $ref: "#/components/schemas/CustomAttribute"
          description: Tối đa 30 thuộc tính tùy chỉnh được phép đặt cho hồ sơ người dùng
        access_levels:
          type: array
          items:
            $ref: "#/components/schemas/AccessLevel"
          description: Mảng các đối tượng mức độ truy cập. Mảng rỗng nếu khách hàng không có mức độ truy cập nào
        subscriptions:
          type: array
          items:
            $ref: "#/components/schemas/Subscription"
          description: Mảng các đối tượng gói đăng ký. Mảng rỗng nếu khách hàng không có gói đăng ký nào
        non_subscriptions:
          type: array
          items:
            $ref: "#/components/schemas/NonSubscription"
          description: Mảng các đối tượng sản phẩm không phải gói đăng ký. Mảng rỗng nếu khách hàng không có giao dịch mua nào
      required:
        - app_id
        - profile_id
        - customer_user_id
        - total_revenue_usd
        - segment_hash
        - timestamp
        - custom_attributes
        - access_levels
        - subscriptions
        - non_subscriptions
    CustomAttribute:
      type: object
      properties:
        key:
          type: string
          maxLength: 30
          description: Khóa phải là chuỗi không quá 30 ký tự. Chỉ cho phép chữ cái, số, dấu gạch ngang, dấu chấm và dấu gạch dưới
        value:
          oneOf:
            - type: string
            - type: number
          description: Giá trị thuộc tính không được quá 50 ký tự. Chỉ cho phép chuỗi và số thực làm giá trị
      required:
        - key
        - value
    InstallationMeta:
      type: object
      properties:
        device_id:
          type: string
          format: uuid
          description: Định danh thiết bị duy nhất
        device:
          type: string
          nullable: true
          description: Thông tin thiết bị
        locale:
          type: string
          nullable: true
          description: Ngôn ngữ thiết bị
        os:
          type: string
          nullable: true
          description: Thông tin hệ điều hành
        platform:
          type: string
          nullable: true
          enum:
            - iOS
            - macOS
            - iPadOS
            - Android
            - visionOS
            - web
          description: Nền tảng (iOS, Android, v.v.)
        timezone:
          type: string
          nullable: true
          description: Múi giờ thiết bị
        user_agent:
          type: string
          nullable: true
          description: Chuỗi user agent
        app_build:
          type: string
          nullable: true
          description: Phiên bản build ứng dụng
        app_version:
          type: string
          nullable: true
          description: Phiên bản ứng dụng
        adapty_sdk_version:
          type: string
          nullable: true
          description: Phiên bản SDK Adapty
        idfa:
          type: string
          nullable: true
          description: Định danh iOS cho nhà quảng cáo
        idfv:
          type: string
          nullable: true
          description: Định danh iOS cho nhà cung cấp
        advertising_id:
          type: string
          nullable: true
          description: ID quảng cáo Android
        android_id:
          type: string
          nullable: true
          description: ID thiết bị Android
        android_app_set_id:
          type: string
          nullable: true
          description: ID bộ ứng dụng Android
      required:
        - device_id
    AccessLevel:
      type: object
      properties:
        access_level_id:
          type: string
          description: Định danh mức độ truy cập
        store:
          type: string
          description: Cửa hàng nơi mức độ truy cập được mua
        store_product_id:
          type: string
          description: ID sản phẩm trong cửa hàng
        store_base_plan_id:
          type: string
          nullable: true
          description: ID gói cơ bản trong cửa hàng
        store_transaction_id:
          type: string
          description: ID giao dịch trong cửa hàng
        store_original_transaction_id:
          type: string
          description: ID giao dịch gốc trong cửa hàng
        offer:
          allOf:
            - $ref: "#/components/schemas/OfferDTO"
          nullable: true
          description: Thông tin ưu đãi, nếu có áp dụng ưu đãi hoặc ưu đãi giới thiệu
        starts_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm mức độ truy cập bắt đầu
        purchased_at:
          type: string
          format: date-time
          description: Thời điểm mức độ truy cập được mua
        originally_purchased_at:
          type: string
          format: date-time
          description: Thời điểm mức độ truy cập được mua lần đầu
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm mức độ truy cập hết hạn
        renewal_cancelled_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm gia hạn bị hủy
        billing_issue_detected_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm phát hiện vấn đề thanh toán
        is_in_grace_period:
          type: boolean
          description: Liệu mức độ truy cập có đang trong thời gian ân hạn hay không
        cancellation_reason:
          type: string
          nullable: true
          description: Lý do hủy
    Subscription:
      type: object
      properties:
        store:
          type: string
          description: Cửa hàng nơi gói đăng ký được mua
        store_product_id:
          type: string
          description: ID sản phẩm trong cửa hàng
        store_base_plan_id:
          type: string
          nullable: true
          description: ID gói cơ bản trong cửa hàng
        store_transaction_id:
          type: string
          description: ID giao dịch trong cửa hàng
        store_original_transaction_id:
          type: string
          description: ID giao dịch gốc trong cửa hàng
        offer:
          allOf:
            - $ref: "#/components/schemas/OfferDTO"
          nullable: true
          description: Thông tin ưu đãi, nếu có áp dụng ưu đãi hoặc ưu đãi giới thiệu
        environment:
          type: string
          description: Môi trường (Sandbox, Production)
        purchased_at:
          type: string
          format: date-time
          description: Thời điểm gói đăng ký được mua
        originally_purchased_at:
          type: string
          format: date-time
          description: Thời điểm gói đăng ký được mua lần đầu
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm gói đăng ký hết hạn
        renewal_cancelled_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm gia hạn bị hủy
        billing_issue_detected_at:
          type: string
          format: date-time
          nullable: true
          description: Thời điểm phát hiện vấn đề thanh toán
        is_in_grace_period:
          type: boolean
          description: Liệu gói đăng ký có đang trong thời gian ân hạn hay không
        cancellation_reason:
          type: string
          nullable: true
          description: Lý do hủy
    NonSubscription:
      type: object
      properties:
        purchase_id:
          type: string
          format: uuid
          description: Định danh giao dịch mua duy nhất
        store:
          type: string
          description: Cửa hàng nơi thực hiện giao dịch mua
        store_product_id:
          type: string
          description: ID sản phẩm trong cửa hàng
        store_base_plan_id:
          type: string
          nullable: true
          description: ID gói cơ bản trong cửa hàng
        store_transaction_id:
          type: string
          description: ID giao dịch trong cửa hàng
        store_original_transaction_id:
          type: string
          description: ID giao dịch gốc trong cửa hàng
        purchased_at:
          type: string
          format: date-time
          description: Thời điểm thực hiện giao dịch mua
        environment:
          type: string
          description: Môi trường (Sandbox, Production)
        is_refund:
          type: boolean
          description: Liệu đây có phải là hoàn tiền hay không
        is_consumable:
          type: boolean
          description: Liệu đây có phải là giao dịch mua consumable hay không
    OfferDTO:
      type: object
      properties:
        category:
          type: string
          enum:
            - introductory
            - promotional
            - offer_code
            - win_back
          description: Danh mục ưu đãi
        type:
          type: string
          enum:
            - free_trial
            - pay_as_you_go
            - pay_up_front
          description: Loại ưu đãi
        id:
          type: string
          nullable: true
          description: ID ưu đãi
      required:
        - category
        - type
  securitySchemes:
    apikeyAuth:
      type: apiKey
      name: Authorization
      in: header
      default: Api-Key {Your secret API key}
      description: |
        Các yêu cầu API phải được xác thực bằng secret API key của bạn trong header **Authorization**
        với giá trị `Api-Key {your_secret_api_key}`, ví dụ:
        `Api-Key secret_live_...`. Tìm key này trong Adapty Dashboard ->
        **App Settings** -> tab **General** -> phần **API keys**.
```
