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

> Create a new manual emission entry for a historical period

# Create Historical Emission

Create a new manual emission entry. The scope is automatically derived from the category. The entry is included in your organization's total emissions.

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

### Body Parameters

<ParamField body="start_date" type="string" required>
  Start date of the emission period (ISO 8601)

  **Example:** `"2022-01-01"`
</ParamField>

<ParamField body="end_date" type="string" required>
  End date of the emission period. Must be greater than or equal to `start_date`.

  **Example:** `"2022-12-31"`
</ParamField>

<ParamField body="category" type="string" required>
  Emission category. Determines the GHG scope automatically.

  **Scope 1:** `process`, `recharge`, `stationary`, `transport`, `waste_water_treatment_population`, `waste_water_treatment_sludge`, `waste_water_treatment_water`

  **Scope 2:** `electricity`

  **Scope 3:** `purchases`, `travels`, `wastes`, `capex`, `employees_in_itinere`, `employees_in_labore`, `electricity_generation`, `electricity_transmission_and_distribution`, `stationary_generation`, `transport_generation`, `transport_distribution_upstream`, `transport_distribution_downstream`, `sold_products_waste`, `use_of_product_combustion`, `use_of_product_electricity`, `use_of_product_water`, `waste_water_treatment_discharge`, `water`
</ParamField>

<ParamField body="total_co2e" type="number" required>
  Total CO2e emissions in kilograms. Must be greater than 0.

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

<ParamField body="description" type="string">
  Free text description of the emission entry

  **Example:** `"2022 electricity consumption from utility bills"`
</ParamField>

<ParamField body="file_id" type="string">
  UUID of an uploaded evidence file to attach
</ParamField>

<ParamField body="file_url" type="string">
  URL of the evidence file
</ParamField>

<ParamField body="file_name" type="string">
  Name of the evidence file (max 255 characters)
</ParamField>

## Response

Returns the created historical emission object with HTTP 201.

<ResponseField name="id" type="string">
  Historical emission UUID
</ResponseField>

<ResponseField name="organization_id" type="string">
  Organization UUID
</ResponseField>

<ResponseField name="start_date" type="date">
  Start date of the emission period (ISO 8601)
</ResponseField>

<ResponseField name="end_date" type="date">
  End date of the emission period (ISO 8601)
</ResponseField>

<ResponseField name="scope" type="integer">
  GHG scope automatically derived from category (1, 2, or 3)
</ResponseField>

<ResponseField name="category" type="string">
  Emission category (e.g. `electricity`, `transport`, `purchases`)
</ResponseField>

<ResponseField name="total_co2e" type="number">
  Total CO2e emissions in kilograms
</ResponseField>

<ResponseField name="description" type="string | null">
  Free text description of the emission entry
</ResponseField>

<ResponseField name="ghg_gas" type="string">
  GHG gas type (e.g. `co2e`)
</ResponseField>

<ResponseField name="ghg_type" type="integer">
  GHG type: `0` = fossil, `1` = biomass
</ResponseField>

<ResponseField name="enabled" type="boolean">
  Whether this emission entry is enabled and included in totals
</ResponseField>

<ResponseField name="file_id" type="string | null">
  UUID of the attached evidence file
</ResponseField>

<ResponseField name="file_url" type="string | null">
  URL of the attached evidence file
</ResponseField>

<ResponseField name="file_name" type="string | null">
  Name of the attached evidence file
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Creation timestamp (ISO 8601)
</ResponseField>

<ResponseField name="updated_at" type="string | null">
  Last update timestamp (ISO 8601)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/historical-emissions" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "start_date": "2022-01-01",
      "end_date": "2022-12-31",
      "category": "electricity",
      "total_co2e": 45200.5,
      "description": "2022 electricity consumption from utility bills"
    }'
  ```

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

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  response = requests.post(
      "https://api.dcycle.io/v1/historical-emissions",
      headers=headers,
      json={
          "start_date": "2022-01-01",
          "end_date": "2022-12-31",
          "category": "electricity",
          "total_co2e": 45200.5,
          "description": "2022 electricity consumption from utility bills",
      },
  )

  entry = response.json()
  print(f"Created: {entry['id']} (scope {entry['scope']})")
  ```

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

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  axios.post('https://api.dcycle.io/v1/historical-emissions', {
    start_date: '2022-01-01',
    end_date: '2022-12-31',
    category: 'electricity',
    total_co2e: 45200.5,
    description: '2022 electricity consumption from utility bills',
  }, { headers })
  .then(response => console.log(`Created: ${response.data.id}`));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "organization_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
  "start_date": "2022-01-01",
  "end_date": "2022-12-31",
  "scope": 2,
  "category": "electricity",
  "total_co2e": 45200.5,
  "description": "2022 electricity consumption from utility bills",
  "ghg_gas": "co2e",
  "ghg_type": 0,
  "enabled": true,
  "file_id": null,
  "file_url": null,
  "file_name": null,
  "created_at": "2024-03-15T10:30:00Z",
  "updated_at": null
}
```

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

### 422 Validation Error

**Cause:** `end_date` is before `start_date`

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "end_date"],
      "msg": "end_date must be greater than or equal to start_date",
      "type": "value_error"
    }
  ]
}
```

**Cause:** `total_co2e` is not positive

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "total_co2e"],
      "msg": "ensure this value is greater than 0",
      "type": "value_error.number.not_gt"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List" icon="list" href="/api-reference/historical-emissions/list">
    View all historical emissions
  </Card>

  <Card title="Update" icon="pencil" href="/api-reference/historical-emissions/update">
    Modify an existing entry
  </Card>
</CardGroup>
