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

# Download Excel

> Queue an async Excel export of custom KPI values

# Download Excel

Queue an asynchronous Excel export of custom KPI values for a dataset. The export is processed in the background and you receive an email with the download link when ready.

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="dataset_id" type="string" required>
  UUID of the dataset to export
</ParamField>

### Body Parameters

<ParamField body="selected_kpi_ids" type="string[]" default="[]">
  KPI UUIDs to include in the export (max 100). Empty array exports all KPIs.
</ParamField>

<ParamField body="selected_campaign_ids" type="string[]" default="[]">
  Campaign UUIDs to include (max 100). Empty array exports all campaigns.
</ParamField>

<ParamField body="language" type="string" default="es">
  Export language: `es` (Spanish) or `en` (English)
</ParamField>

## Response (202 Accepted)

<ResponseField name="message" type="string">
  Confirmation message
</ResponseField>

<ResponseField name="queued" type="boolean">
  Always `true` — the export is processing asynchronously
</ResponseField>

<ResponseField name="processing_job_id" type="string">
  UUID of the processing job for tracking progress
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/custom-kpi-datasets/${DATASET_ID}/download_excel" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "selected_kpi_ids": [],
      "selected_campaign_ids": [],
      "language": "en"
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  response = requests.post(
      f"https://api.dcycle.io/v1/custom-kpi-datasets/{os.getenv('DATASET_ID')}/download_excel",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "Content-Type": "application/json",
      },
      json={
          "selected_kpi_ids": [],
          "selected_campaign_ids": [],
          "language": "en",
      },
  )

  result = response.json()
  print(f"Export queued — job ID: {result['processing_job_id']}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const response = await axios.post(
    `https://api.dcycle.io/v1/custom-kpi-datasets/${process.env.DATASET_ID}/download_excel`,
    {
      selected_kpi_ids: [],
      selected_campaign_ids: [],
      language: 'en',
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'Content-Type': 'application/json',
      },
    }
  );

  console.log(`Export queued — job ID: ${response.data.processing_job_id}`);
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "message": "Custom KPI download queued. You will receive an email when ready.",
  "queued": true,
  "processing_job_id": "job-uuid"
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 404 Not Found

**Cause:** The dataset does not exist or belongs to another organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Not Found"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Dataset Values" icon="table" href="/api-reference/custom-kpi/list-dataset-values">
    View values in the browser
  </Card>

  <Card title="Get Dataset" icon="database" href="/api-reference/custom-kpi/get-dataset">
    View dataset details
  </Card>
</CardGroup>
