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

# Sync Datasource

### Overview

The Databrain APIs provides endpoints to sync you Datasource in both Cloud Databrain and Selfhosted Databrain environment. To use the API, you need to pass a parameter `datasourceId`.

## Self-hosted Databrain Endpoint

```bash theme={"dark"}
POST <SELF_HOSTED_URL>/api/v2/datasource/sync
```

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer [API TOKEN](https://docs.usedatabrain.com/developer-docs/helpers/api-token)
</ParamField>

## Request Body

<ParamField body="input" type="object" required>
  Input object containing the datasource configuration.

  <ParamField body="input.datasourceId" type="string" required>
    The unique identifier of the datasource to sync. You can find this in the URL query params on the datasource page.
  </ParamField>
</ParamField>

## Request Example

<RequestExample>
  ```bash cURL theme={"dark"}
  curl --request POST \
    --url https://api.usedatabrain.com/api/v2/datasource/sync \
    --header 'Authorization: Bearer dbn_live_abc123...' \
    --header 'Content-Type: application/json' \
    --data '{
      "input": {
        "datasourceId": "your-datasource-id"
      }
    }'
  ```

  ```javascript Node.js theme={"dark"}
  const response = await fetch('https://api.usedatabrain.com/api/v2/datasource/sync', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer dbn_live_abc123...',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      input: {
        datasourceId: 'your-datasource-id'
      }
    })
  });

  const data = await response.json();
  console.log(data.data.message);
  ```

  ```python Python theme={"dark"}
  import requests

  response = requests.post(
      'https://api.usedatabrain.com/api/v2/datasource/sync',
      headers={
          'Authorization': 'Bearer dbn_live_abc123...',
          'Content-Type': 'application/json'
      },
      json={
          'input': {
              'datasourceId': 'your-datasource-id'
          }
      }
  )

  data = response.json()
  print(data['data']['message'])
  ```
</RequestExample>

## Response Body

<ResponseExample>
  ```json theme={"dark"}
  {
    "data": {
      "message": "Sync completed"
    }
  }
  ```
</ResponseExample>

> Get your `datasourceId` from the URL query params on the datasource page.

<Frame>
  <Image src="/images/guides/datasource-sync.png" />
</Frame>

## Error Codes

* **INVALID\_REQUEST\_BODY**: The request body is invalid.
* **DATASOURCE\_ID\_ERROR**: The datasource ID provided does not exist or is invalid.
