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

# Get Consent Set by ID

> Retrieve a specific consent set with all consent records

## Overview

Retrieves a specific consent set by its UUID, including all consent records with detailed metadata.

<Info>
  Use this endpoint when you have a `consentSetId` and need to retrieve the complete consent set details.
</Info>

## Endpoint

```
GET https://api.baanx.com/v2/consent/consentSet/{consentSetId}
```

## Headers

| Header         | Required | Description                         |
| -------------- | -------- | ----------------------------------- |
| `x-client-key` | ✅        | Your public API key                 |
| `x-us-env`     | ❌        | Set to `true` for US region routing |

## Path Parameters

| Parameter      | Type          | Required | Description                         |
| -------------- | ------------- | -------- | ----------------------------------- |
| `consentSetId` | string (UUID) | ✅        | UUID of the consent set to retrieve |

## Response

### 200 OK

```json theme={null}
{
  "consentSetId": "550e8400-e29b-41d4-a716-446655440001",
  "userId": "user_123abc456def",
  "onboardingId": "onboarding_abc123xyz",
  "tenantId": "tenant_baanx_prod",
  "policyType": "global",
  "completedAt": "2024-01-15T10:35:00Z",
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:35:00Z",
  "consents": [
    {
      "consentId": "consent_001",
      "consentType": "eSignAct",
      "consentStatus": "granted",
      "metadata": {
        "timestamp": "2024-01-15T10:30:00Z",
        "ipAddress": "192.168.1.1",
        "userAgent": "Mozilla/5.0..."
      },
      "createdAt": "2024-01-15T10:30:00Z",
      "updatedAt": "2024-01-15T10:30:00Z"
    },
    {
      "consentId": "consent_002",
      "consentType": "termsAndPrivacy",
      "consentStatus": "granted",
      "metadata": {
        "timestamp": "2024-01-15T10:30:00Z"
      },
      "createdAt": "2024-01-15T10:30:00Z",
      "updatedAt": "2024-01-15T10:30:00Z"
    }
  ],
  "_links": {
    "self": {
      "href": "https://api.baanx.com/v2/consent/consentSet/550e8400-e29b-41d4-a716-446655440001",
      "method": "GET"
    },
    "audit": {
      "href": "https://api.baanx.com/v2/consent/user/user_123abc456def/audit",
      "method": "GET"
    }
  }
}
```

### Response Fields

| Field          | Type              | Description                              |
| -------------- | ----------------- | ---------------------------------------- |
| `consentSetId` | string (UUID)     | Unique identifier for this consent set   |
| `userId`       | string\|null      | User identifier (null if not yet linked) |
| `onboardingId` | string            | Temporary onboarding identifier          |
| `tenantId`     | string            | Tenant identifier                        |
| `policyType`   | string            | Policy type: `global` or `US`            |
| `completedAt`  | string\|null      | When user was linked (null if pending)   |
| `createdAt`    | string (ISO 8601) | When consent set was created             |
| `updatedAt`    | string (ISO 8601) | Last update timestamp                    |
| `consents`     | array             | Array of consent records                 |

### 404 Not Found

```json theme={null}
{
  "error": "Not found",
  "details": [
    "Consent set with ID '550e8400-e29b-41d4-a716-446655440001' not found"
  ]
}
```

## Code Examples

### TypeScript

```typescript theme={null}
async function getConsentSetById(consentSetId: string) {
  const response = await fetch(
    `https://api.baanx.com/v2/consent/consentSet/${consentSetId}`,
    {
      headers: {
        'x-client-key': process.env.BAANX_CLIENT_KEY!
      }
    }
  );

  if (!response.ok) {
    const error = await response.json();
    throw new Error(`Failed to retrieve consent set: ${error.details.join(', ')}`);
  }

  return response.json();
}

const consentSet = await getConsentSetById('550e8400-e29b-41d4-a716-446655440001');
console.log(`Consent set for user: ${consentSet.userId}`);
console.log(`Total consents: ${consentSet.consents.length}`);
```

### Python

```python theme={null}
import requests

def get_consent_set_by_id(consent_set_id):
    response = requests.get(
        f'https://api.baanx.com/v2/consent/consentSet/{consent_set_id}',
        headers={
            'x-client-key': os.getenv('BAANX_CLIENT_KEY')
        }
    )

    response.raise_for_status()
    return response.json()

consent_set = get_consent_set_by_id('550e8400-e29b-41d4-a716-446655440001')
print(f"User: {consent_set['userId']}")
print(f"Policy: {consent_set['policyType']}")
```

### cURL

```bash theme={null}
curl -X GET "https://api.baanx.com/v2/consent/consentSet/550e8400-e29b-41d4-a716-446655440001" \
  -H "x-client-key: your_client_key"
```

## Use Cases

<AccordionGroup>
  <Accordion title="Verify Linking Status">
    Check if a consent set has been linked to a user:

    ```typescript theme={null}
    async function isConsentSetLinked(consentSetId: string): Promise<boolean> {
      const consentSet = await getConsentSetById(consentSetId);
      return consentSet.userId !== null && consentSet.completedAt !== null;
    }
    ```
  </Accordion>

  <Accordion title="Retrieve Specific Consent">
    Find a specific consent within the set:

    ```typescript theme={null}
    async function getSpecificConsent(
      consentSetId: string,
      consentType: string
    ) {
      const consentSet = await getConsentSetById(consentSetId);

      return consentSet.consents.find(c => c.consentType === consentType);
    }

    const marketingConsent = await getSpecificConsent(
      '550e8400-e29b-41d4-a716-446655440001',
      'marketingNotifications'
    );
    ```
  </Accordion>

  <Accordion title="Policy Verification">
    Verify the policy type for a consent set:

    ```typescript theme={null}
    async function verifyPolicyType(
      consentSetId: string,
      expectedPolicy: 'global' | 'US'
    ): Promise<boolean> {
      const consentSet = await getConsentSetById(consentSetId);
      return consentSet.policyType === expectedPolicy;
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get by Onboarding ID" icon="magnifying-glass" href="/api-reference/consent/get-onboarding-consent">
    Retrieve consent sets by onboarding ID
  </Card>

  <Card title="Get User Consent Status" icon="circle-check" href="/api-reference/consent/get-user-consent">
    Get consent status by userId
  </Card>

  <Card title="Link User to Consent" icon="link" href="/api-reference/consent/link-user-to-consent">
    Link userId to this consent set
  </Card>
</CardGroup>
