> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/user/user.getconsenteddata.md).

# User.getConsentedData

> Functional API `getConsentedUserData`You can use the same functionality with it as well.

### Feature description

We request consent-based user data. If consent is needed, it opens the terms webview, and once consent is completed, returns the data retrieved from the server.

Toss app **5.264.0** can be used on versions above. Before calling, `User.getConsentedData.isSupported()`You can check whether it is supported with. Function-style API `getConsentedUserData`returns it in unsupported versions, `undefined`and `User.getConsentedData`is `UNSUPPORTED_APP_VERSION` throws an error.

### Type

```ts
User.getConsentedData(options: GetConsentedUserDataOptions): Promise<ConsentedUserData>;
```

**Params**

```ts
interface GetConsentedUserDataOptions {
  /** The key used by the server to find the consent statement and data bundle for user data provision. Example: `cud_delivery` */
  consentedUserDataKey: string;
  /** Whether to open the terms webview again even in the `USER_DECLINED` state. The default value is `false`. */
  shouldRequestAgreementWhenUserDeclined?: boolean;
}
```

**Response**

```ts
type ConsentedUserDataKey =
  | "USER_NAME"
  | "USER_GENDER"
  | "USER_NATIONALITY"
  | "USER_BIRTHDAY"
  | "USER_PHONE"
  | "USER_ADDRESS"
  | "USER_EMAIL"
  | "USER_CONSUMPTION_HISTORY";

type ConsentedUserData = Partial<Record<ConsentedUserDataKey, string>>;
```

Only the keys corresponding to the requested items may be included.

### Error

The error code is the `error.code` value.

| Code                                   | Description                                                                                                                                                                                                                                 |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UNSUPPORTED_APP_VERSION`              | If the running Toss app version does not support this feature, it occurs immediately upon calling. `User.getConsentedData.isSupported()`Check in advance with, and if it occurs `error.message`show the user the (update guidance message). |
| `USER_DECLINED`                        | This is the case when the user explicitly declined and there is no re-request option, or when they declined consent in the terms WebView.                                                                                                   |
| `UNAVAILABLE`                          | This is the case when the server cannot determine whether the user has consented.                                                                                                                                                           |
| `TERMS_NOT_SET`                        | This is the case when the user data consent statement is not set in the mini app.                                                                                                                                                           |
| `INVALID_REQUEST`                      | `consentedUserDataKey`is empty, or `termsUrl`is missing, or is not an HTTPS company domain.                                                                                                                                                 |
| `CANCELED`                             | This is the case when the terms WebView is closed before it sends a result.                                                                                                                                                                 |
| `CONSENTED_USER_DATA_AGREEMENT_FAILED` | This is the case when an error occurs while handling the terms WebView.                                                                                                                                                                     |
| `CONSENTED_USER_DATA_INVALID_DATA`     | `PROVIDED`but `data`is missing, or the re-query result after consent success is `PROVIDED`not.                                                                                                                                              |

### Example code

```js
import { User } from "@apps-in-toss/web-framework";

async function fetchDeliveryUserData() {
  try {
    const data = await User.getConsentedData({
      consentedUserDataKey: "cud_delivery",
    });

    console.log("User name:", data?.USER_NAME);
    console.log("Phone number:", data?.USER_PHONE);
  } catch (error) {
    console.error("Failed to fetch consent data:", error);
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-en/sdk/domains-api/user/user.getconsenteddata.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
