# Lấy hồ sơ người dùng

> Truy xuất thông tin chi tiết của người dùng cuối hiện có trong ứng dụng của bạn.

## OpenAPI

```yaml
/api-specs/adapty-api.yaml get /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/:
    get:
      summary: Lấy hồ sơ người dùng
      description: Truy xuất thông tin chi tiết của người dùng cuối hiện có trong ứng dụng của bạn.
      operationId: getProfile
      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`.
      responses:
        "200":
          description: Hồ sơ người dùng được truy xuất thành công
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ProfileResponse"
              example:
                data:
                  app_id: 14c3d333-2f3a-455a-aa86-ef83dff6913b
                  profile_id: d8533a10-bcce-4e33-8c9d-88b05ac56559
                  customer_user_id: 77B14FB4-FD2A-4D38-AA3A-4C433F79863C
                  total_revenue_usd: 9.99
                  segment_hash: fdaeef7f8aaa33c9
                  timestamp: 1733324566777
                  custom_attributes:
                    - key: favourite_sport
                      value: yoga
                  access_levels:
                    - access_level_id: premium
                      store: app_store
                      store_product_id: unlimited.9999
                      store_base_plan_id: null
                      store_transaction_id: "2000000335013007"
                      store_original_transaction_id: "2000000335013007"
                      offer: null
                      starts_at: null
                      purchased_at: "2024-12-24T10:50:23+00:00"
                      originally_purchased_at: "2024-12-24T10:50:23+00:00"
                      expires_at: null
                      renewal_cancelled_at: "2025-01-05T13:27:47.461425+00:00"
                      billing_issue_detected_at: null
                      is_in_grace_period: false
                      cancellation_reason: null
                  subscriptions:
                    - store: app_store
                      store_product_id: unlimited.9999
                      store_base_plan_id: null
                      store_transaction_id: "2000000815013007"
                      store_original_transaction_id: "2000000815013007"
                      offer: null
                      environment: Sandbox
                      purchased_at: "2024-12-24T10:50:23+00:00"
                      originally_purchased_at: "2024-12-24T10:50:23+00:00"
                      expires_at: null
                      renewal_cancelled_at: null
                      billing_issue_detected_at: null
                      is_in_grace_period: false
                      cancellation_reason: null
                  non_subscriptions:
                    - purchase_id: 7a5f9a7d-e236-33e6-96d8-53a3c59c5562
                      store: app_store
                      store_product_id: 1year.premium
                      store_base_plan_id: null
                      store_transaction_id: "30002109551456"
                      store_original_transaction_id: "30002109551456"
                      purchased_at: "2022-10-12T09:42:50+00:00"
                      environment: Production
                      is_refund: false
                      is_consumable: false
        "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
        "404":
          description: Không tìm thấy hồ sơ người dùng
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                errors:
                  - source: null
                    errors:
                      - Profile not found
                error_code: profile_does_not_exist
                status_code: 404
        "500":
          description: Lỗi máy chủ nội bộ
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
    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
    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**.
```
