> ## 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 Sets by Onboarding ID

> Retrieve all consent sets associated with an onboarding ID

## Overview

Retrieves all consent sets associated with a specific `onboardingId`. Useful for recovering consent set information during registration flows.

<Info>
  This endpoint returns **all** consent sets created with the given `onboardingId`, including those that may have already been linked to users.
</Info>

## Endpoint

```
GET https://api.baanx.com/v2/consent/onboarding/{onboardingId}
```

## 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                                        |
| -------------- | ------ | -------- | -------------------------------------------------- |
| `onboardingId` | string | ✅        | Onboarding identifier used during consent creation |

## Response

### 200 OK

```json theme={null}
{
  "onboardingId": "onboarding_abc123xyz",
  "consentSets": [
    {
      "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"
          },
          "createdAt": "2024-01-15T10:30:00Z",
          "updatedAt": "2024-01-15T10:30:00Z"
        }
      ]
    }
  ],
  "_links": {
    "self": {
      "href": "https://api.baanx.com/v2/consent/onboarding/onboarding_abc123xyz",
      "method": "GET"
    }
  }
}
```

### 404 Not Found

```json theme={null}
{
  "error": "Not found",
  "details": [
    "No consent sets found for onboardingId 'onboarding_abc123xyz'"
  ]
}
```

## Code Examples

### TypeScript

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

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

  return response.json();
}

const { consentSets } = await getConsentSetsByOnboardingId('onboarding_abc123xyz');
console.log(`Found ${consentSets.length} consent set(s)`);
```

### Python

```python theme={null}
import requests

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

    response.raise_for_status()
    return response.json()

result = get_consent_sets_by_onboarding_id('onboarding_abc123xyz')
print(f"Found {len(result['consentSets'])} consent set(s)")
```

### cURL

```bash theme={null}
curl -X GET "https://api.baanx.com/v2/consent/onboarding/onboarding_abc123xyz" \
  -H "x-client-key: your_client_key"
```

## Use Cases

<AccordionGroup>
  <Accordion title="Session Recovery">
    Recover consent set ID from onboarding ID:

    ```typescript theme={null}
    async function recoverConsentSetId(onboardingId: string): Promise<string | null> {
      try {
        const { consentSets } = await getConsentSetsByOnboardingId(onboardingId);

        if (consentSets.length === 0) {
          return null;
        }

        return consentSets[0].consentSetId;
      } catch (error) {
        console.error('Failed to recover consent set:', error);
        return null;
      }
    }

    const consentSetId = await recoverConsentSetId('onboarding_abc123xyz');
    ```
  </Accordion>

  <Accordion title="Duplicate Detection">
    Check if onboarding ID has already been used:

    ```typescript theme={null}
    async function hasExistingConsent(onboardingId: string): Promise<boolean> {
      try {
        const { consentSets } = await getConsentSetsByOnboardingId(onboardingId);
        return consentSets.length > 0;
      } catch (error) {
        if (error.status === 404) {
          return false;
        }
        throw error;
      }
    }
    ```
  </Accordion>

  <Accordion title="Link Status Check">
    Verify if consent set has been linked:

    ```typescript theme={null}
    async function isOnboardingComplete(onboardingId: string): Promise<boolean> {
      const { consentSets } = await getConsentSetsByOnboardingId(onboardingId);

      return consentSets.some(cs => cs.userId !== null && cs.completedAt !== null);
    }
    ```
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get by Consent Set ID" icon="magnifying-glass" href="/api-reference/consent/get-consent-set">
    Retrieve specific consent set
  </Card>

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

  <Card title="Create Onboarding Consent" icon="plus" href="/api-reference/consent/create-onboarding-consent">
    Create new consent set with onboarding ID
  </Card>
</CardGroup>
