> ## 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.

# Export LCA to Excel

> Export LCA impact results to an Excel spreadsheet

# Export LCA to Excel

Exports the environmental impact results of an LCA portfolio to an Excel file. The file is uploaded to S3 and a presigned download URL is returned.

## 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>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

### Path Parameters

<ParamField path="lca_id" type="string" required>
  UUID of the LCA portfolio to export

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

### Body Parameters

<ParamField body="category_impacts" type="array" required>
  List of impact categories to include in the export (max 50)

  <Expandable title="CategoryImpactItem">
    <ResponseField name="key" type="string" required>
      Impact category key (lowercase, underscores only, max 100 chars)

      **Example:** `gwp`, `ap`, `ep_freshwater`
    </ResponseField>

    <ResponseField name="name" type="string" required>
      Human-readable name for the impact category (max 200 chars)

      **Example:** `Global Warming Potential`, `Acidification`
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField body="recursive" type="boolean" default="false">
  Include child processes recursively in the export
</ParamField>

<ParamField body="max_depth" type="integer" default="10">
  Maximum depth of the process tree to include (1-10)
</ParamField>

<ParamField body="view" type="string" default="system">
  Visualization mode for the export

  | Value           | Description                                                       |
  | --------------- | ----------------------------------------------------------------- |
  | `system`        | Absolute impact of the whole system (no allocation)               |
  | `product_total` | Impact allocated to one co-product (requires `output_product_id`) |
  | `product_unit`  | Per-unit impact of one co-product (requires `output_product_id`)  |
</ParamField>

<ParamField body="output_product_id" type="string">
  UUID of the co-product for `product_total` or `product_unit` views. Required when `view` is not `system`.
</ParamField>

## Response

<ResponseField name="download_url" type="string">
  Presigned S3 URL to download the Excel file. The URL expires after a limited time.
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/lca/export-xlsx/${LCA_ID}" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "category_impacts": [
        {"key": "gwp", "name": "Global Warming Potential"},
        {"key": "ap", "name": "Acidification"}
      ],
      "recursive": true,
      "max_depth": 5,
      "view": "system"
    }'
  ```

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

  lca_id = "550e8400-e29b-41d4-a716-446655440000"

  response = requests.post(
      f"https://api.dcycle.io/v1/lca/export-xlsx/{lca_id}",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      },
      json={
          "category_impacts": [
              {"key": "gwp", "name": "Global Warming Potential"},
              {"key": "ap", "name": "Acidification"},
          ],
          "recursive": True,
          "max_depth": 5,
          "view": "system",
      },
  )

  result = response.json()
  print(f"Download: {result['download_url']}")
  ```

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

  const lcaId = '550e8400-e29b-41d4-a716-446655440000';

  axios.post(`https://api.dcycle.io/v1/lca/export-xlsx/${lcaId}`, {
    category_impacts: [
      { key: 'gwp', name: 'Global Warming Potential' },
      { key: 'ap', name: 'Acidification' },
    ],
    recursive: true,
    max_depth: 5,
    view: 'system',
  }, {
    headers: {
      'x-api-key': process.env.DCYCLE_API_KEY,
      'x-organization-id': process.env.DCYCLE_ORG_ID,
    },
  })
  .then(({ data }) => {
    console.log(`Download: ${data.download_url}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "download_url": "https://dcycle-exports.s3.eu-west-1.amazonaws.com/org-id/Results%20LCA%20My%20Product.xlsx?X-Amz-Algorithm=..."
}
```

### Co-product View Example

To export impacts allocated to a specific co-product:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "category_impacts": [
    {"key": "gwp", "name": "Global Warming Potential"}
  ],
  "recursive": true,
  "view": "product_total",
  "output_product_id": "c3d4e5f6-a7b8-9012-cdef-345678901234"
}
```

## 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:** LCA portfolio not found or doesn't belong to your organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "LCA Portfolio not found"}
```

### 422 Unprocessable Entity

**Cause:** Invalid view value or missing `output_product_id` for co-product views

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "view"],
      "msg": "view must be one of ['product_total', 'product_unit', 'system']",
      "type": "value_error"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get LCA Impacts" icon="chart-bar" href="/api-reference/lca/impacts">
    Calculate impacts before exporting
  </Card>

  <Card title="LCA Dashboard" icon="chart-pie" href="/api-reference/lca/dashboard">
    View aggregated impact results in the UI
  </Card>

  <Card title="Get LCA Portfolio" icon="magnifying-glass" href="/api-reference/lca/get">
    View portfolio details
  </Card>
</CardGroup>
