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

> Create a custom emission factor record

[← Custom Emission Factors](/api-reference/custom-emission-factors/overview)

A record is one emission factor. Its `id` is what your data references, e.g. `custom_ef_record_id` in [`POST /v2/wastes`](/api-reference/wastes/create-v2).

<Warning>
  **Beta.** Part of the custom emission factors API, currently in beta. The contract may still change before general
  availability.
</Warning>

<RequestExample>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v1/emission-factors/custom-databases/5f1c2e7a-3b4d-4e8f-9a01-2c3d4e5f6a7b/versions/7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d/records" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Mixed packaging - Ecoveza plant",
      "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
      "tag": "simple",
      "activity_categories": [
        "wastes"
      ],
      "factors": [
        {
          "gas_type": "co2e",
          "value": "0.21"
        }
      ]
    }'
  ```

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

  import requests

  response = requests.post(
      "https://api.dcycle.io/v1/emission-factors/custom-databases/5f1c2e7a-3b4d-4e8f-9a01-2c3d4e5f6a7b/versions/7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d/records",
      headers={
          "x-api-key": os.environ["DCYCLE_API_KEY"],
          "x-organization-id": os.environ["DCYCLE_ORG_ID"],
      },
      json={
          "name": "Mixed packaging - Ecoveza plant",
          "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
          "tag": "simple",
          "activity_categories": [
              "wastes"
          ],
          "factors": [
              {
                  "gas_type": "co2e",
                  "value": "0.21"
              }
          ]
      },
      timeout=30,
  )
  response.raise_for_status()
  print(response.json())
  ```

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

  const response = await axios.post('https://api.dcycle.io/v1/emission-factors/custom-databases/5f1c2e7a-3b4d-4e8f-9a01-2c3d4e5f6a7b/versions/7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d/records', {
    "name": "Mixed packaging - Ecoveza plant",
    "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
    "tag": "simple",
    "activity_categories": [
      "wastes"
    ],
    "factors": [
      {
        "gas_type": "co2e",
        "value": "0.21"
      }
    ]
  }, {
    headers: {
      'x-api-key': process.env.DCYCLE_API_KEY,
      'x-organization-id': process.env.DCYCLE_ORG_ID,
    },
  });
  console.log(response.status, response.data);
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={"theme":{"light":"github-light","dark":"github-dark"}}
  {
    "id": "c3d4e5f6-a7b8-9012-cdef-ab3456789012",
    "name": "Mixed packaging - Ecoveza plant",
    "unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
    "source_id": "7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d",
    "tag": "simple",
    "additional_docs": null,
    "evidence": [],
    "uncertainty_grade": "0",
    "is_biogenic": false,
    "renewable_percentage": null,
    "enabled": true,
    "activity_categories": [
      "wastes"
    ],
    "factors": [
      {
        "id": "1e2d3c4b-5a69-4788-9a0b-1c2d3e4f5a6b",
        "source_id": "7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d",
        "concept_id": "2f3e4d5c-6b7a-4899-8a0b-2c3d4e5f6a7b",
        "from_unit_id": "61743a63-ff70-459c-9567-5eee8f7dfd5c",
        "to_unit_id": "0b1c2d3e-4f5a-4b6c-8d7e-9f0a1b2c3d4e",
        "formula": "x * 0.21",
        "start_date": "1970-01-01",
        "end_date": null,
        "gas_type": "co2e"
      }
    ]
  }
  ```
</ResponseExample>

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

<ParamField path="database_id" type="uuid" required>
  The database id.

  **Example:** `5f1c2e7a-3b4d-4e8f-9a01-2c3d4e5f6a7b`
</ParamField>

<ParamField path="source_id" type="uuid" required>
  The version id (`id` of the version).

  **Example:** `7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d`
</ParamField>

### Body Parameters

<ParamField body="name" type="string" required>
  Record name, 1 to 255 characters. Make it recognizable: it is what users pick from.

  **Example:** `"Mixed packaging - Ecoveza plant"`
</ParamField>

<ParamField body="unit_id" type="uuid" required>
  Unit of the **activity** the factor applies to (e.g. kilogram for wastes). Must match the unit your data will be in.

  **Example:** `"61743a63-ff70-459c-9567-5eee8f7dfd5c"`
</ParamField>

<ParamField body="tag" type="string" required>
  Which gases the record carries.

  **Available values:** `simple` (one `co2e` factor), `advanced` (one `co2`, one `ch4` and one `n2o`), `full` (one of
  each: `co2e`, `co2`, `ch4`, `n2o`).
</ParamField>

<ParamField body="activity_categories" type="array[string]" required>
  At least one category that may use the record, e.g. `["wastes"]`. See
  [Activity categories](/api-reference/custom-emission-factors/overview#activity-categories).
</ParamField>

<ParamField body="factors" type="array[object]" required>
  The factor values, one per gas, matching `tag`. Each gas may appear once.

  <Expandable title="factor fields">
    <ParamField body="gas_type" type="string" required>
      **Available values:** `co2e`, `co2`, `ch4`, `n2o`.
    </ParamField>

    <ParamField body="value" type="number" required>
      Emissions per unit of activity: kg for `co2e` and `co2`, **grams** for `ch4` and `n2o`. Send it as a string
      (`"0.21"`) to keep decimals exact.
    </ParamField>

    <ParamField body="start_date" type="date" default="1970-01-01">
      First day the factor applies.
    </ParamField>

    <ParamField body="end_date" type="date | null">
      Last day it applies; omit for open-ended. Must be on or after `start_date`.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="enabled" type="boolean" default="true">
  Disabled records stay in the database but new data cannot use them.
</ParamField>

<ParamField body="is_biogenic" type="boolean" default="false">
  Report the CO2 factor as biogenic. Requires a `co2` factor, and only the `stationary`, `process` and `transport`
  categories.
</ParamField>

<ParamField body="renewable_percentage" type="number | null">
  Renewable share between 0 and 1. Electricity categories only.
</ParamField>

<ParamField body="uncertainty_grade" type="number" default="0">
  Uncertainty grade of the factor.
</ParamField>

## Response

The created record (`201 Created`):

<ResponseField name="id" type="uuid">Record id: the value your data references (e.g. `custom_ef_record_id` on a waste).</ResponseField>
<ResponseField name="name" type="string">Record name.</ResponseField>
<ResponseField name="unit_id" type="uuid">Unit of the activity the factor applies to.</ResponseField>
<ResponseField name="source_id" type="uuid">Version the record belongs to.</ResponseField>
<ResponseField name="tag" type="string">**Available values:** `simple`, `advanced`, `full`.</ResponseField>
<ResponseField name="activity_categories" type="array[string]">Categories that can use the record.</ResponseField>
<ResponseField name="enabled" type="boolean">Only enabled records can be used by new data.</ResponseField>
<ResponseField name="is_biogenic" type="boolean">Whether the CO2 factor is reported as biogenic.</ResponseField>
<ResponseField name="renewable_percentage" type="number | null">Renewable share (electricity only).</ResponseField>
<ResponseField name="uncertainty_grade" type="number">Uncertainty grade.</ResponseField>
<ResponseField name="additional_docs" type="string | null">URL of the first evidence document, if any.</ResponseField>
<ResponseField name="evidence" type="array[object]">Evidence documents: `file_id`, `file_name`, `file_url`, `size_kb`.</ResponseField>

<ResponseField name="factors" type="array[object]">
  One per gas.

  <Expandable title="factor fields">
    <ResponseField name="id" type="uuid">Factor id.</ResponseField>
    <ResponseField name="gas_type" type="string">`co2e`, `co2`, `ch4` or `n2o`.</ResponseField>
    <ResponseField name="formula" type="string">The factor applied to the activity quantity `x`, e.g. `x * 0.21`.</ResponseField>
    <ResponseField name="from_unit_id" type="uuid">The record's `unit_id`.</ResponseField>
    <ResponseField name="to_unit_id" type="uuid">Unit of the result: kg CO2e, kg CO2, g CH4 or g N2O.</ResponseField>
    <ResponseField name="start_date" type="date">First day the factor applies.</ResponseField>
    <ResponseField name="end_date" type="date | null">Last day it applies; `null` means open-ended.</ResponseField>
    <ResponseField name="source_id" type="uuid">Version of the record.</ResponseField>
    <ResponseField name="concept_id" type="uuid">Internal concept id.</ResponseField>
  </Expandable>
</ResponseField>

## Common Errors

### 401 Unauthorized

Missing or invalid API key.

### 403 Forbidden

`LOGGED_USER_NOT_MEMBER`: the API key's user is not a member of the organization in `x-organization-id`.

### 404 Not Found

`CUSTOM_DATABASE_NOT_FOUND` or `CUSTOM_VERSION_NOT_FOUND`: the database or version does not exist or is not visible to
your organization.

### 403 CUSTOM\_DATABASE\_NOT\_OWNER

Only the organization that owns the database can create or change its records.

### 422 Unprocessable Entity

| `code` | Cause |
| - | - |
| `CUSTOM_RECORD_INVALID_FACTORS` | The factors do not match `tag` (e.g. a `simple` record without exactly one `co2e`). |
| `CUSTOM_RECORD_INVALID_CATEGORIES` | An `activity_categories` value does not exist. |
| `CUSTOM_RECORD_BIOGENIC_CATEGORY` | `is_biogenic` on a category other than stationary, process or transport. |
| `CUSTOM_RECORD_BIOGENIC_REQUIRES_CO2` | `is_biogenic` without a `co2` factor. |
| `CUSTOM_RECORD_RENEWABLE_CATEGORY` | `renewable_percentage` on a non-electricity category. |

A malformed body (missing field, wrong type) answers the standard validation format: `{"detail": [{"loc": [...], "msg": "...", "type": "..."}]}`.

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Record" icon="magnifying-glass" href="/api-reference/custom-emission-factors/get-record">
    One record by id
  </Card>

  <Card title="Update Record" icon="pencil" href="/api-reference/custom-emission-factors/update-record">
    Change a record
  </Card>
</CardGroup>
