> 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 feature with it as well.

### Feature description

Requests user-consent-based data. If consent is required, it opens the terms webview, and once consent is complete, it returns the data retrieved from the server.

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

### Type

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

**Params**

```ts
interface GetConsentedUserDataOptions {
  /** This is the key the server uses to find the user data provision consent text and data bundle. 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 can be included.

### Error

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

| Code                                   | Description                                                                                                                                                                                                                                     |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UNSUPPORTED_APP_VERSION`              | If the running version of the Toss app doesn't support this feature, it occurs immediately upon call. `User.getConsentedData.isSupported()`Check in advance with `error.message`and, if it occurs, show the user the (update guidance message). |
| `USER_DECLINED`                        | This is the case when the user explicitly declined and there is no retry request option, or when they declined 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 mini app does not have the user data provision consent text set.                                                                                                                                                      |
| `INVALID_REQUEST`                      | `consentedUserDataKey`is empty, or `termsUrl`is missing, or it is not an HTTPS company domain.                                                                                                                                                  |
| `CANCELED`                             | This is the case when the terms webview is closed before sending the result.                                                                                                                                                                    |
| `CONSENTED_USER_DATA_AGREEMENT_FAILED` | An error occurred while processing the terms webview.                                                                                                                                                                                           |
| `CONSENTED_USER_DATA_INVALID_DATA`     | `PROVIDED`but `data`is missing, or after successful consent the re-query result 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 retrieve 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.
