---
sourceType: api-reference
sourceTypeMatchedRule: openApis
slug: MA/openApis/partner/apis/appPermission
title: Quản lý Quyền Mini App
---
Cho phép đối tác lấy danh sách các Quyền mặc định của hệ thống kèm trạng thái hiện tại của Mini App, và gửi yêu cầu đăng ký một hoặc nhiều quyền.

## 1. Lấy danh sách Permission

Trả về toàn bộ quyền của hệ thống cùng trạng thái đăng ký hiện tại của Mini App.

### Parameters

| Property | Type   | Required | Description               |
| -------- | ------ | -------- | ------------------------- |
| appId    | String | true     | ID của Mini App tương ứng |

### Return Values

| Property    | Type                   | Description                                              |
| ----------- | ---------------------- | -------------------------------------------------------- |
| error       | int                    | Mã lỗi của kết quả trả về, bằng 0 nếu request thành công |
| message     | String                 | Lời nhắn chi tiết tương ứng với mã lỗi                   |
| total       | int                    | Tổng số permission của hệ thống                          |
| permissions | List AppPermissionItem | Danh sách permission                                     |

### AppPermissionItem

| Property     | Type   | Description                                                        |
| ------------ | ------ | ------------------------------------------------------------------ |
| permissionId | int    | ID của permission                                                  |
| name         | String | Tên permission                                                     |
| description  | String | Mô tả permission                                                   |
| action       | String | Hành động tương ứng của permission                                 |
| status       | Enum   | Trạng thái đăng ký: `UNREGISTERED`, `WAITING_APPROVAL`, `APPROVED` |
| consentText  | String | Nội dung consent hiển thị cho người dùng                           |

#### Sample Code


### Code sample — Java

```js
import com.vng.zalo.miniapp.openapi.sdk.models.GetPermissionsRequest;
import com.vng.zalo.miniapp.openapi.sdk.models.GetPermissionsResponse;

GetPermissionsRequest request = new GetPermissionsRequest();
request.setMiniAppId(Long.parseLong(System.getenv("MINI_APP_ID")));

GetPermissionsResponse response = client.getAppPermissions(request);
System.out.println(response);
```

### Code sample — Node.js

```js
const { total, permissions, error, message } =
  await partnerClient.getAppPermissions({
    appId: "your_mini_app_id",
  });
```

## 2. Đăng ký Permission

Gửi yêu cầu đăng ký một hoặc nhiều permission cho Mini App. Chỉ các permission có trạng thái `UNREGISTERED` mới cần đăng ký. Kết quả có thể thành công một phần — kiểm tra `successPermissions` để xem các permission nào được chấp nhận.

Vòng đời trạng thái: `UNREGISTERED` → `WAITING_APPROVAL` → `APPROVED`

### Parameters

| Property    | Type                       | Required | Description                      |
| ----------- | -------------------------- | -------- | -------------------------------- |
| appId       | String                     | true     | ID của Mini App tương ứng        |
| note        | String                     | false    | Ghi chú lý do đăng ký permission |
| permissions | List RequestPermissionItem | true     | Danh sách permission cần đăng ký |

### RequestPermissionItem

| Property     | Type   | Required | Description                                        |
| ------------ | ------ | -------- | -------------------------------------------------- |
| permissionId | int    | true     | ID của permission (lấy từ API lấy danh sách)       |
| consentText  | String | false    | Nội dung consent tùy chỉnh hiển thị cho người dùng |

### Return Values

| Property           | Type     | Description                                              |
| ------------------ | -------- | -------------------------------------------------------- |
| error              | int      | Mã lỗi của kết quả trả về, bằng 0 nếu request thành công |
| message            | String   | Lời nhắn chi tiết tương ứng với mã lỗi                   |
| successPermissions | List int | Danh sách ID các permission đã được đăng ký thành công   |

#### Sample Code

### Code sample — Java

```js
import com.vng.zalo.miniapp.openapi.sdk.models.RequestPermissionRequest;
import com.vng.zalo.miniapp.openapi.sdk.models.RequestPermissionResponse;
import com.vng.zalo.miniapp.openapi.sdk.models.AppPermission;
import java.util.Arrays;

AppPermission perm1 = new AppPermission();
perm1.setPermissionId(25);
perm1.setConsentText("Ứng dụng cần quyền này để cung cấp dịch vụ tốt hơn");

AppPermission perm2 = new AppPermission();
perm2.setPermissionId(38);

RequestPermissionRequest request = new RequestPermissionRequest();
request.setMiniAppId({Your Mini App's Id});
request.setNote("Yêu cầu quyền truy cập thông tin người dùng");
request.setPermissions(Arrays.asList(perm1, perm2));

RequestPermissionResponse response = client.requestAppPermission(request);
System.out.println("Đăng ký thành công: " + response.getSuccessPermissions());
```

### Code sample — Node.js

```js
const { successPermissions, error, message } =
  await partnerClient.requestAppPermission({
    appId: "your_mini_app_id",
    note: "Yêu cầu quyền truy cập thông tin người dùng",
    permissions: [
      {
        permissionId: 25,
        consentText: "Ứng dụng cần quyền này để cung cấp dịch vụ tốt hơn",
      },
      {
        permissionId: 38,
      },
    ],
  });
```
