# Customer data and privacy requests

> Answer a customer who asks to see their data, to prove they consented, or to be deleted, with the calls that do each today and what each leaves behind.

Privacy laws such as the GDPR and the CCPA give your customers the right to see what you hold about them, to know
what they agreed to, and to have their account deleted. The realm holds the evidence for each request: the
customer's profile, a record of every app they allowed and when, and an audit trail of what was done in their name.
This page maps each request to the calls that answer it today. One-call export is planned, and customers can't yet
delete their own account; you do both for them.

## Before you begin

- **Privilege:** `RealmViewer` in the customer realm to read a customer's data and trail; `RealmOwner` to change or
  delete their account. Give the people who handle privacy requests a group with only what they need; see
  [Delegated administration](/platform/realms/delegated-administration/).
- **Where:** the API. [Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`.
- **The customer's sign-in name,** here `maya`, and their id, which their record carries.
- **Check it's them** by your own means before you act on a request.

## How it works

| Request | What answers it | How |
|---|---|---|
| See my data | Their record, their consent records, their factors and their audit trail | [Give a customer their data](#give-a-customer-their-data) |
| What did I agree to? | Their consent records: each app, the scopes allowed, `firstGranted` and `lastGranted` | [Prove consent](#prove-consent) |
| Withdraw my consent from an app | The customer's own **Authorized Apps** page | [Authorized apps](../../self-service/authorized-apps/) |
| Correct my data | A change to their record | `PATCH` on their record; see [Add and change users](/directory/users/add-and-change-users/) |
| Delete me | Ending their access, then deleting the account | [Delete a customer's account](#delete-a-customers-account) |

## Give a customer their data

Read each part, and hand the customer the answers:

```sh
# Their profile, without their password
curl https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"

# Every app they allowed
curl -G https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Consent \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  --data-urlencode 'filter={"filter":{"field":"subjectId","op":"=","value":"<maya'\''s id>"}}'

# What was done by them and in their name
curl "https://foobar.cvyuh.com/api/v0/am/audit/v1/trail?person=<maya's id>&pageSize=100" \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

A customer can read most of it themselves, with their own session: their profile (`POST /whoami/v1`), their factors
(`GET /devices/v1`), the apps they allowed (`GET /me/v1/oauth2/apps`) and their own trail (`GET /audit/v1/trail/me`).
See [Self-service](/directory/users/self-service/) and [Read a user's or agent's trail](/audit-reports/audit-trail/read-a-trail/).

## Prove consent

Each `oauth2Consent` record names the customer (`subjectId`), the app (`clientId`), every scope they allowed it, when
they first allowed it anything (`firstGranted`) and when they last allowed it more (`lastGranted`):

```json
{ "subjectId": "<maya's id>", "clientId": "example-app", "scopes": ["email", "openid", "profile"],
  "firstGranted": "<RFC 3339 time>", "lastGranted": "<RFC 3339 time>" }
```

A record exists only while the consent stands: taking an app back removes it, and leaves an `APP_TAKEN_BACK` record
on the customer's trail with the time. Keep your own copy of a record if you need proof after it's withdrawn.

Consent here is to apps and scopes. Acceptance of your terms or privacy policy isn't recorded by the realm; record it
in your own app.

## Delete a customer's account

Deleting the account record alone doesn't end everything the customer holds. Do it in this order:

1. **Stop their access.** Turn the account off, so sign-in and new tokens stop at once:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "status": "inactive" }'
   ```

2. **End their sessions:**

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/sessions/v1/end \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "qbe": { "filter": { "field": "user", "op": "=", "value": "maya" } } }'
   ```

3. **Keep what you must.** Read and save their trail and consent records if your own retention rules require them.

4. **Remove their consent records,** each by the `id` the list above returns:

   ```sh
   curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Consent/<record id> \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "If-Match: *"
   ```

5. **Delete the account:**

   ```sh
   curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "If-Match: *"
   ```

### What goes with the account

| Goes | Stays |
|---|---|
| The account and its profile | Their audit trail, under their id |
| Their group memberships, and every agent's right to act for them | Consent records you didn't remove in step 4 |
| Their personal secrets, if they kept any in Secrets Store | Their passkey and authenticator-app records, which no one can use, since no account holds them |
| New tokens and refreshes: the realm refuses them, and introspection answers inactive | Access tokens an API checks on its own, without introspection, until they expire |

A deleted account can't be brought back. If the customer might return, leave the account inactive instead.

## Limits and defaults

| What | Today |
|---|---|
| One-call export of a customer's data | Planned: see [What's next for lifecycle](/directory/lifecycle/whats-next/#personal-data-export) |
| A customer deleting their own account | Not offered: your app calls the delete for them |
| How long the audit trail is kept | See [Retention](/audit-reports/audit-trail/retention/) |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| `DELETE` on the account answers `412` | The `If-Match` revision is stale | Send `If-Match: *`, or the current revision |
| A deleted customer's app still reaches your API | The API checks tokens on its own, and the token hasn't expired | Turn the account off and end sessions before deleting, as above; keep access tokens short |
| The consent list is empty for a customer who allowed apps | The filter names their sign-in name, not their id | Use the `id` from their record |

## Audit records

Each change is on the trail: the account turned off and deleted (`PATCHED`, `DELETED`, with the record before the
change), and each consent record removed (`DELETED`). Read them in
[Change history](/audit-reports/audit-trail/change-history/) and on the customer's trail.

## Related

- [Authorized apps](../../self-service/authorized-apps/): customers withdraw consent from an app themselves.
- [The consent page](../consent-page/): how consent is given.
- [Turn access off and on](/directory/users/turn-access-off-and-on/): what `status` stops.
- [Retention](/platform/data/retention/): how long the realm keeps data.
