# Cấp mức độ truy cập

> Cung cấp mức độ truy cập cho người dùng cuối mà không cần cung cấp thông tin giao dịch. Điều này rất hữu ích khi bạn có phần thưởng giới thiệu hoặc các sự kiện khác liên quan đến sản phẩm của bạn. Mức độ truy cập được cung cấp bởi phương thức này sẽ không được phản ánh trong phân tích của bạn. Nó sẽ chỉ được gửi tới tích hợp webhook, và chỉ trong trường hợp này mới xuất hiện trong Event Feed.

## OpenAPI

```yaml
/api-specs/adapty-api.yaml post /api/v2/server-side-api/purchase/profile/grant/access-level/
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/purchase/profile/grant/access-level/:
    post:
      summary: Cấp mức độ truy cập
      description: Cung cấp mức độ truy cập cho người dùng cuối mà không cần cung cấp thông tin giao dịch. Điều này rất hữu ích khi bạn có phần thưởng giới thiệu hoặc các sự kiện khác liên quan đến sản phẩm của bạn. Mức độ truy cập được cung cấp bởi phương thức này sẽ không được phản ánh trong phân tích của bạn. Nó sẽ chỉ được gửi tới tích hợp webhook, và chỉ trong trường hợp này mới xuất hiện trong Event Feed.
      operationId: grantAccessLevel
      tags:
        - Purchase
      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: Mức độ truy cập được cấp thành công
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ProfileResponse"
        "400":
          description: Yêu cầu không hợp lệ
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: Không được phép
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "404":
          description: Không tìm thấy hồ sơ người dùng
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: Lỗi máy chủ nội bộ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/GrantAccessRequest"
            examples:
              immediate_grant:
                summary: Cấp quyền truy cập ngay lập tức
                value:
                  access_level_id: premium
              scheduled_grant:
                summary: Cấp quyền truy cập với ngày bắt đầu và kết thúc
                value:
                  access_level_id: premium
                  starts_at: "2024-01-01T00:00:00Z"
                  expires_at: "2024-12-31T23:59:59Z"
              lifetime_grant:
                summary: Cấp quyền truy cập trọn đời
                value:
                  access_level_id: premium
                  starts_at: "2024-01-01T00:00:00Z"
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
    GrantAccessRequest:
      type: object
      properties:
        access_level_id:
          type: string
          description: ID mức độ truy cập trả phí được cấu hình trong trang Access Levels
        starts_at:
          type: string
          format: date-time
          nullable: true
          description: Ngày giờ khi mức độ truy cập sẽ được kích hoạt. Có thể là trong tương lai. Giá trị mặc định là null.
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: Ngày giờ khi mức độ truy cập sẽ hết hạn. Có thể là trong quá khứ và có thể là null cho quyền truy cập trọn đời. Giá trị mặc định là null.
      required:
        - access_level_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
    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**.
```
