> ## Documentation Index
> Fetch the complete documentation index at: https://docs.grantex.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# List Consent Records

> List all DPDP consent records for the developer, with optional filtering by data principal.

## Endpoint

```
GET /v1/dpdp/consent-records
```

## Authentication

Requires a developer API key in the `Authorization` header.

## Request Headers

| Header          | Value              |
| --------------- | ------------------ |
| `Authorization` | `Bearer <api_key>` |

## Query Parameters

| Parameter         | Type     | Required | Description                         |
| ----------------- | -------- | -------- | ----------------------------------- |
| `dataPrincipalId` | `string` | No       | Filter records by data principal ID |

## Example Request

```bash theme={null}
curl "https://grantex-auth-dd4mtrt2gq-uc.a.run.app/v1/dpdp/consent-records?dataPrincipalId=user_abc123" \
  -H "Authorization: Bearer gx_..."
```

## Response -- 200 OK

```json theme={null}
{
  "records": [
    {
      "recordId": "cr_01HXYZ...",
      "grantId": "grnt_01HXYZ...",
      "dataPrincipalId": "user_abc123",
      "dataFiduciaryName": "Acme Corp",
      "purposes": [
        { "code": "analytics", "description": "Usage analytics" }
      ],
      "scopes": ["calendar:read"],
      "consentNoticeId": "notice_v2",
      "status": "active",
      "consentGivenAt": "2026-04-05T12:00:00.000Z",
      "processingExpiresAt": "2027-01-01T00:00:00.000Z",
      "retentionUntil": "2027-01-31T00:00:00.000Z",
      "accessCount": 2,
      "withdrawnAt": null,
      "createdAt": "2026-04-05T12:00:00.000Z"
    }
  ],
  "totalRecords": 1
}
```

## Response Fields

| Field          | Type       | Description                      |
| -------------- | ---------- | -------------------------------- |
| `records`      | `object[]` | Array of consent record objects  |
| `totalRecords` | `number`   | Total number of records returned |

### Record Object

| Field                 | Type             | Description                                                  |
| --------------------- | ---------------- | ------------------------------------------------------------ |
| `recordId`            | `string`         | Unique consent record ID                                     |
| `grantId`             | `string`         | The associated grant ID                                      |
| `dataPrincipalId`     | `string`         | The data principal who gave consent                          |
| `dataFiduciaryName`   | `string`         | Name of the data fiduciary (developer)                       |
| `purposes`            | `object[]`       | Array of purpose objects (`{ code, description }`)           |
| `scopes`              | `string[]`       | Scopes from the associated grant                             |
| `consentNoticeId`     | `string`         | ID of the consent notice                                     |
| `status`              | `string`         | Record status: `active`, `withdrawn`, `expired`, or `erased` |
| `consentGivenAt`      | `string`         | ISO-8601 timestamp of original consent                       |
| `processingExpiresAt` | `string`         | ISO-8601 processing expiry timestamp                         |
| `retentionUntil`      | `string`         | ISO-8601 data retention limit                                |
| `accessCount`         | `number`         | Number of times this record has been accessed                |
| `withdrawnAt`         | `string \| null` | ISO-8601 timestamp of withdrawal (if withdrawn)              |
| `createdAt`           | `string`         | ISO-8601 creation timestamp                                  |

## Error Responses

| Status | Code           | Description                |
| ------ | -------------- | -------------------------- |
| 401    | `UNAUTHORIZED` | Invalid or missing API key |

## SDK Examples

<CodeGroup>
  ```typescript TypeScript theme={null}
  import Grantex from '@grantex/sdk';

  const grantex = new Grantex({ apiKey: 'gx_...' });

  // List all consent records
  const all = await grantex.dpdp.listConsentRecords();

  // Filter by data principal
  const filtered = await grantex.dpdp.listConsentRecords({
    dataPrincipalId: 'user_abc123',
  });
  ```

  ```python Python theme={null}
  from grantex import Grantex

  grantex = Grantex(api_key="gx_...")

  # List all consent records
  all_records = grantex.dpdp.list_consent_records()

  # Filter by data principal
  filtered = grantex.dpdp.list_consent_records(
      data_principal_id="user_abc123",
  )
  ```
</CodeGroup>
