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

# Recalculate Employees

> Enqueue async emission recalculation for selected employee commuting periods

# Recalculate Employees

Enqueue EF-config recalculation for a set of employees' commuting periods. The endpoint returns `202 Accepted` immediately and creates one `ProcessingJob` per requested activity category.

<Note>
  All employee IDs must belong to the caller's organization. IDs that don't match are silently dropped. The service resolves every enabled commuting period (`employees_historic`) of the owned employees and enqueues them for recalculation.
</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>

### Body Parameters

<ParamField body="employee_ids" type="array of strings" required>
  One or more employee UUIDs to recalculate. Must be non-empty. Maximum 5000 IDs.

  **Example:** `["a1b2c3d4-...", "e5f6g7h8-..."]`
</ParamField>

<ParamField body="activity_categories" type="array of strings" required>
  Activity categories to recalculate. Must be non-empty. Duplicates are silently deduplicated.

  **Allowed values:**

  * `employee_commuting` — Scope 3 employee commuting emissions

  **Example:** `["employee_commuting"]`
</ParamField>

## Response

<ResponseField name="employee_ids" type="array of strings">
  UUIDs of the employees that were enqueued (after organization scoping).
</ResponseField>

<ResponseField name="count" type="integer">
  Number of employees enqueued.
</ResponseField>

<ResponseField name="processing_job_ids" type="array of strings">
  One `ProcessingJob` UUID per dispatched activity category.
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v2/employees/recalculate" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "employee_ids": [
        "550e8400-e29b-41d4-a716-446655440000",
        "660e8400-e29b-41d4-a716-446655440001"
      ],
      "activity_categories": ["employee_commuting"]
    }'
  ```

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

  response = requests.post(
      "https://api.dcycle.io/v2/employees/recalculate",
      headers={
          "x-api-key": os.getenv("DCYCLE_API_KEY"),
          "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
          "Content-Type": "application/json",
      },
      json={
          "employee_ids": [
              "550e8400-e29b-41d4-a716-446655440000",
              "660e8400-e29b-41d4-a716-446655440001",
          ],
          "activity_categories": ["employee_commuting"],
      },
  )

  result = response.json()
  print(f"Enqueued {result['count']} employees, jobs: {result['processing_job_ids']}")
  ```

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

  const response = await axios.post(
    'https://api.dcycle.io/v2/employees/recalculate',
    {
      employee_ids: [
        '550e8400-e29b-41d4-a716-446655440000',
        '660e8400-e29b-41d4-a716-446655440001',
      ],
      activity_categories: ['employee_commuting'],
    },
    {
      headers: {
        'x-api-key': process.env.DCYCLE_API_KEY,
        'x-organization-id': process.env.DCYCLE_ORG_ID,
        'Content-Type': 'application/json',
      },
    }
  );

  console.log(`Enqueued ${response.data.count} employees`);
  console.log(`Job IDs: ${response.data.processing_job_ids.join(', ')}`);
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "employee_ids": [
    "550e8400-e29b-41d4-a716-446655440000",
    "660e8400-e29b-41d4-a716-446655440001"
  ],
  "count": 2,
  "processing_job_ids": [
    "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  ]
}
```

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

**Cause:** Invalid activity category

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Invalid activity_category: unknown. Allowed: ['employee_commuting']",
  "code": "VALIDATION_ERROR"
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Employees" icon="list" href="/api-reference/employees/list-v2">
    Retrieve employees to find IDs for recalculation
  </Card>

  <Card title="Get Employee" icon="user" href="/api-reference/employees/get">
    Check updated emissions on a single employee
  </Card>
</CardGroup>
