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

# Create LCA from Excel

> Create a complete LCA portfolio by uploading an Excel file

# Create LCA from Excel

Creates a complete LCA portfolio with all its components from an uploaded Excel file. The file must contain two sheets: `process_map` (defining nodes and relationships) and `header` (LCA metadata).

<Note>
  This endpoint requires **API key** authentication only (`x-api-key` header). For JSON-based creation, see [Create from JSON](/api-reference/lca/create-from-json).
</Note>

## Request

### Authentication

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

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

### Headers

<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 `multipart/form-data`
</ParamField>

### Body Parameters

<ParamField body="excel_file" type="file" required>
  Excel file (`.xlsx`) containing the LCA definition
</ParamField>

## Excel File Format

The Excel file must contain two sheets:

### Sheet: `header`

LCA metadata (single row):

| Column              | Type   | Description                                             |
| ------------------- | ------ | ------------------------------------------------------- |
| `name`              | string | LCA portfolio name                                      |
| `description`       | string | Optional description                                    |
| `impact_categories` | string | JSON array of impact category IDs (e.g. `["gwp","ap"]`) |
| `unit_id`           | string | UUID of the functional unit                             |
| `value`             | number | Functional unit quantity                                |
| `start_date`        | string | Start date (`YYYY-MM-DD`)                               |
| `end_date`          | string | End date (`YYYY-MM-DD`)                                 |
| `start_node`        | string | Name of the root process node                           |

### Sheet: `process_map`

Node definitions with parent-child relationships:

| Column         | Type   | Description                                         |
| -------------- | ------ | --------------------------------------------------- |
| `id`           | string | Unique node identifier                              |
| `parent_id`    | string | ID of the parent node (empty for root)              |
| `type`         | string | Node type: `process`, `material`, `energy`, `waste` |
| `name`         | string | Node display name                                   |
| `supplier`     | string | Supplier name                                       |
| `country`      | string | Country code (ISO 3166-1 alpha-2)                   |
| `transport_id` | string | Transport type (e.g. `truck`, `ship`) — optional    |
| `quantity`     | number | Quantity value                                      |
| `unit`         | string | Unit of measurement                                 |

**Example `process_map` sheet:**

```
| id | parent_id | type     | name              | supplier    | country | transport_id | quantity | unit |
|----|-----------|----------|-------------------|-------------|---------|--------------|----------|------|
| 1  |           | process  | Table Assembly    | Factory A   | ES      |              |          |      |
| 2  | 1         | material | Sawn timber       | Forest Co   | FI      | truck        | 15       | kg   |
| 3  | 1         | material | Steel bolts       | Steel Inc   | DE      |              | 0.5      | kg   |
| 4  | 1         | energy   | Electricity       |             | ES      |              | 2.5      | kWh  |
| 5  | 1         | waste    | Wood shavings     |             | ES      |              | 1.2      | kg   |
```

## Response

Returns HTTP 201 with the created LCA information.

<ResponseField name="acv_id" type="string">
  UUID of the created LCA portfolio
</ResponseField>

<ResponseField name="summary" type="object">
  Summary of the created LCA structure
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/lca/create-from-excel" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -F "excel_file=@my_lca.xlsx"
  ```

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

  with open("my_lca.xlsx", "rb") as f:
      response = requests.post(
          "https://api.dcycle.io/v1/lca/create-from-excel",
          headers={
              "x-api-key": os.getenv("DCYCLE_API_KEY"),
              "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          },
          files={"excel_file": ("my_lca.xlsx", f, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")},
      )

  result = response.json()
  print(f"Created LCA: {result['acv_id']}")
  ```

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

  const form = new FormData();
  form.append('excel_file', fs.createReadStream('my_lca.xlsx'));

  axios.post('https://api.dcycle.io/v1/lca/create-from-excel', form, {
    headers: {
      'x-api-key': process.env.DCYCLE_API_KEY,
      'x-organization-id': process.env.DCYCLE_ORG_ID,
      ...form.getHeaders(),
    },
  })
  .then(({ data }) => {
    console.log(`Created LCA: ${data.acv_id}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "acv_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "summary": {
    "name": "Wooden Table LCA",
    "nodes_created": 5,
    "processes": 1,
    "materials": 2,
    "energy": 1,
    "waste": 1
  }
}
```

## 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"}
```

### 422 Unprocessable Entity

**Cause:** Invalid Excel structure, missing sheets, or invalid data

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Missing required sheet: 'process_map'"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Create from JSON" icon="code" href="/api-reference/lca/create-from-json">
    Create LCA from a JSON tree structure
  </Card>

  <Card title="List LCA Portfolios" icon="list" href="/api-reference/lca/list">
    Browse all LCA portfolios
  </Card>

  <Card title="LCA Dashboard" icon="chart-pie" href="/api-reference/lca/dashboard">
    View environmental impact results
  </Card>
</CardGroup>
