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

# Get Group Units

> Retrieve all measurement units used in a custom emission group

<Warning>
  **Legacy API.** This page documents the previous version of the API. This particular
  operation has no documented equivalent in the current API yet, so this remains the
  documented way to do it. Prefer the current API for everything it already covers.
</Warning>

Retrieve a list of all measurement units used by emission factors within a specific custom emission group.

<Note>
  This endpoint returns the unique set of units used across all emission factors in the group, useful for validating data consistency or building UI selectors.
</Note>

## 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:** `ff4adcc7-8172-45fe-9cf1-e90a6de53aa9`
</ParamField>

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

  **Example:** `a1b2c3d4-e5f6-7890-abcd-ef1234567890`
</ParamField>

### Path Parameters

<ParamField path="id" type="string" required>
  UUID of the Custom Emission Group
</ParamField>

## Response

Returns an array of unit objects used in the group.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
[
  {
    "id": "kg-unit-uuid",
    "name": "kilogram",
    "abbreviation": "kg",
    "type": "mass"
  },
  {
    "id": "ton-unit-uuid",
    "name": "metric ton",
    "abbreviation": "t",
    "type": "mass"
  }
]
```

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl "https://api.dcycle.io/api/v1/custom_emission_groups/units/group-uuid" \
    -H "Authorization: Bearer ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "x-user-id: ${DCYCLE_USER_ID}"
  ```

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

  headers = {
      "Authorization": f"Bearer {os.getenv('DCYCLE_API_KEY')}",
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "x-user-id": os.getenv("DCYCLE_USER_ID")
  }

  group_id = "group-uuid"

  response = requests.get(
      f"https://api.dcycle.io/api/v1/custom_emission_groups/units/{group_id}",
      headers=headers
  )

  units = response.json()
  print(f"Units used in this group:")
  for unit in units:
      print(f"- {unit['name']} ({unit['abbreviation']})")
  ```

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

  const headers = {
    'Authorization': `Bearer ${process.env.DCYCLE_API_KEY}`,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'x-user-id': process.env.DCYCLE_USER_ID
  };

  const groupId = 'group-uuid';

  axios.get(
    `https://api.dcycle.io/api/v1/custom_emission_groups/units/${groupId}`,
    { headers }
  )
  .then(response => {
    const units = response.data;
    console.log('Units used in this group:');
    units.forEach(unit => {
      console.log(`- ${unit.name} (${unit.abbreviation})`);
    });
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

## Use Cases

### Build Unit Selector

Create a dropdown with available units for the group:

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
async function loadUnitsForGroup(groupId) {
  const units = await axios.get(
    `https://api.dcycle.io/api/v1/custom_emission_groups/units/${groupId}`,
    { headers }
  ).then(res => res.data);

  const options = units.map(unit => ({
    value: unit.id,
    label: `${unit.name} (${unit.abbreviation})`
  }));

  return options;
}
```

### Validate Data Consistency

Check if all factors in a group use the same unit type:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
units = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_groups/units/{group_id}",
    headers=headers
).json()

unit_types = set(unit['type'] for unit in units)

if len(unit_types) == 1:
    print(f"✅ Consistent unit type: {unit_types.pop()}")
else:
    print(f"⚠️ Mixed unit types: {', '.join(unit_types)}")
    print("Consider reviewing factor consistency")
```

### Display Group Statistics

Show unit usage statistics:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
units = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_groups/units/{group_id}",
    headers=headers
).json()

# Get all factors
factors = requests.get(
    f"https://api.dcycle.io/api/v1/custom_emission_factors/list/{group_id}",
    headers=headers,
    params={"page": 1, "size": 100}
).json()

print(f"Group uses {len(units)} different units across {factors['total']} factors:\n")

for unit in units:
    count = sum(1 for f in factors['items'] if f['unit_id'] == unit['id'])
    print(f"- {unit['abbreviation']}: {count} factors")
```

## Response Fields

<ResponseField name="id" type="string">
  Unique identifier for the unit
</ResponseField>

<ResponseField name="name" type="string">
  Full name of the unit (e.g., "kilogram", "liter")
</ResponseField>

<ResponseField name="abbreviation" type="string">
  Standard abbreviation (e.g., "kg", "L")
</ResponseField>

<ResponseField name="type" type="string">
  Unit type (e.g., "mass", "volume", "energy", "currency")
</ResponseField>

## Common Errors

### 404 Not Found

**Cause:** Custom emission group not found

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Custom emission group not found",
  "code": "NOT_FOUND"
}
```

**Solution:** Verify the group ID exists.

### Empty Array

If the group has no emission factors yet, this endpoint returns an empty array `[]`.

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Factors" icon="list" href="/api-docs/custom-emission-factors/list">
    View all factors in group
  </Card>

  <Card title="Get Group" icon="magnifying-glass" href="/api-docs/custom-emission-groups/get">
    View group details
  </Card>

  <Card title="All Units" icon="ruler" href="/api-reference/legacy/units/list">
    List all available units
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.