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

# Validate Authentication

> Validates the provided Bearer token and returns user information

Validates the provided Bearer token and returns user information. This endpoint is useful for testing your authentication setup and verifying that your integration key is working correctly.

## Use Cases

* **Health Check**: Verify your integration key is valid and active
* **User Identification**: Get the user ID associated with your integration key
* **Connection Testing**: Test your API setup before making other requests
* **Debugging**: Troubleshoot authentication issues

## Response Details

A successful response confirms that:

* Your Bearer token is valid and properly formatted
* The integration key exists in our system
* The associated user account is active
* You can proceed to make other API requests

The `user_id` in the response can be used for:

* Creating integration configurations
* Tracking API usage
* Debugging and support requests

## Common Issues

<AccordionGroup>
  <Accordion title="401 - Authorization header with Bearer token required">
    **Cause**: Missing or malformed Authorization header

    **Solution**: Include `Authorization: Bearer YOUR_INTEGRATION_KEY` in your request headers

    ```bash theme={null}
    # ✅ Correct format
    curl -H "Authorization: Bearer 550e8400-e29b-41d4-a716-446655440000"

    # ❌ Common mistakes
    curl -H "Authorization: YOUR_INTEGRATION_KEY"  # Missing "Bearer "
    curl -H "Bearer YOUR_INTEGRATION_KEY"         # Missing "Authorization:"
    ```
  </Accordion>

  <Accordion title="401 - Bearer token is empty">
    **Cause**: Authorization header is present but the token value after "Bearer " is empty

    **Solution**: Ensure your integration key is properly set in your environment or configuration

    ```javascript theme={null}
    // Check your environment variable is set
    console.log(process.env.CARDCLAN_API_KEY); // Should not be undefined

    const headers = {
      'Authorization': `Bearer ${process.env.CARDCLAN_API_KEY}`
    };
    ```
  </Accordion>

  <Accordion title="404 - Invalid bearer token - user not found">
    **Cause**: The integration key is not valid or doesn't exist in our system

    **Solution**:

    * Verify you're using the correct integration key
    * Check if the key was regenerated and update your configuration
    * Generate a new key if necessary using the [Create Key](/api-reference/authentication/create-key) endpoint
  </Accordion>
</AccordionGroup>

## Response Example

```json theme={null}
{
  "success": true,
  "message": "Bearer token authentication successful",
  "user_id": "60f7b2b5b8f4a20015a4f5a3"
}
```

## Testing Your Setup

Use this endpoint to test your authentication setup:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.cardclan.com/api/integration/auth/validate" \
    -H "Authorization: Bearer YOUR_INTEGRATION_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.cardclan.com/api/integration/auth/validate', {
    headers: {
      Authorization: `Bearer ${process.env.CARDCLAN_API_KEY}`,
    },
  });

  if (response.ok) {
    const data = await response.json();
    console.log('Authentication successful:', data);
  } else {
    console.error('Authentication failed:', await response.json());
  }
  ```

  ```python Python theme={null}
  import requests
  import os

  headers = {
      'Authorization': f'Bearer {os.getenv("CARDCLAN_API_KEY")}'
  }

  response = requests.get(
      'https://api.cardclan.com/api/integration/auth/validate',
      headers=headers
  )

  if response.status_code == 200:
      print('Authentication successful:', response.json())
  else:
      print('Authentication failed:', response.json())
  ```
</CodeGroup>


## OpenAPI

````yaml GET /integration/auth/validate
openapi: 3.1.0
info:
  title: CardClan Integration API
  description: >-
    The CardClan Integration API enables third-party applications and automation
    platforms to send personalized digital cards, manage workflows, and
    integrate CardClan's functionality into existing systems.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://app.cardclan.io/api
security:
  - bearerAuth: []
paths:
  /integration/auth/validate:
    get:
      tags:
        - Authentication
      summary: Validate Authentication
      description: Validates the provided Bearer token and returns user information
      responses:
        '200':
          description: Authentication successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthValidationResponse'
        '401':
          description: Invalid or missing authentication
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Invalid token - user not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    AuthValidationResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        message:
          type: string
          example: Bearer token authentication successful
        user_id:
          type: string
          example: 60f7b2b5b8f4a20015a4f5a3
    Error:
      type: object
      properties:
        error:
          type: string
          example: Bad Request
        message:
          type: string
          example: Card ID is required
        statusCode:
          type: number
          example: 400
        timestamp:
          type: string
          format: date-time
          example: '2024-01-15T10:30:00.000Z'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Enter your CardClan integration key

````