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

> Create a single logistics recharge (fuel consumption record) for your organization

# Create Logistics Recharge

Create a new fuel consumption record for a logistics vehicle. A recharge records fuel usage (diesel, electric, etc.) linked to a specific fuel type and optionally a vehicle and project.

## 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="fuel_id" type="string" required>
  UUID of the fuel type from the `logistic_fuels` table. Use [`GET /logistics/fuels`](/api-reference/logistics/get-fuels) to list all available fuel IDs and their names.

  **Example:** `550e8400-e29b-41d4-a716-446655440000`
</ParamField>

<ParamField body="country" type="string" required>
  Country ISO 3166-1 alpha-2 code where the recharge took place.

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

<ParamField body="date" type="string" required>
  Date of the recharge in `YYYY-MM-DD` format.

  **Example:** `2025-06-15`
</ParamField>

<ParamField body="quantity" type="number">
  Amount of fuel consumed, in the fuel's unit (e.g., liters for diesel, kWh for electricity).

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

<ParamField body="vehicle_license_plate" type="string">
  License plate of the vehicle that was refueled.

  **Example:** `1234-ABC`
</ParamField>

<ParamField body="toc_id" type="string">
  UUID of the vehicle type (TOC) associated with this recharge. Use the GET /tocs endpoint to get available TOC IDs.
</ParamField>

<ParamField body="project_id" type="string">
  UUID of a project to associate this recharge with.
</ParamField>

## Response

Returns the created (or upserted) recharge with HTTP 201.

<ResponseField name="id" type="string">
  Recharge UUID
</ResponseField>

<ResponseField name="fuel_id" type="string">
  UUID of the fuel type
</ResponseField>

<ResponseField name="fuel_name" type="string">
  Display name of the fuel (e.g. `Diesel`, `Electricity`)
</ResponseField>

<ResponseField name="country" type="string">
  ISO-2 country code
</ResponseField>

<ResponseField name="date" type="date">
  Recharge date (ISO 8601)
</ResponseField>

<ResponseField name="quantity" type="number">
  Fuel quantity in the fuel's unit
</ResponseField>

<ResponseField name="vehicle_license_plate" type="string | null">
  License plate of the vehicle
</ResponseField>

<ResponseField name="toc_id" type="string | null">
  UUID of the associated vehicle type (TOC)
</ResponseField>

<ResponseField name="unit_name" type="string">
  Unit of measurement (e.g. `liters`, `kWh`, `kg`)
</ResponseField>

<ResponseField name="status" type="string">
  Record status: `active` or `deleted`
</ResponseField>

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

<ResponseField name="updated_at" type="datetime | 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/logistics/recharges" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "fuel_id": "550e8400-e29b-41d4-a716-446655440000",
      "country": "ES",
      "date": "2025-06-15",
      "quantity": 50.0,
      "vehicle_license_plate": "1234-ABC"
    }'
  ```

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

  api_key = os.getenv("DCYCLE_API_KEY")
  org_id = os.getenv("DCYCLE_ORG_ID")

  headers = {
      "x-api-key": api_key,
      "x-organization-id": org_id,
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://api.dcycle.io/v1/logistics/recharges",
      headers=headers,
      json={
          "fuel_id": "550e8400-e29b-41d4-a716-446655440000",
          "country": "ES",
          "date": "2025-06-15",
          "quantity": 50.0,
          "vehicle_license_plate": "1234-ABC"
      }
  )

  result = response.json()
  print(f"Recharge ID: {result['id']}")
  print(f"Fuel: {result['fuel_name']}")
  ```

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

  const apiKey = process.env.DCYCLE_API_KEY;
  const orgId = process.env.DCYCLE_ORG_ID;

  const headers = {
    'x-api-key': apiKey,
    'x-organization-id': orgId,
    'Content-Type': 'application/json'
  };

  axios.post(
    'https://api.dcycle.io/v1/logistics/recharges',
    {
      fuel_id: '550e8400-e29b-41d4-a716-446655440000',
      country: 'ES',
      date: '2025-06-15',
      quantity: 50.0,
      vehicle_license_plate: '1234-ABC'
    },
    { headers }
  )
  .then(response => {
    console.log(`Recharge ID: ${response.data.id}`);
    console.log(`Fuel: ${response.data.fuel_name}`);
  })
  .catch(error => console.error(error));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "660e8400-e29b-41d4-a716-446655440000",
  "fuel_id": "550e8400-e29b-41d4-a716-446655440000",
  "fuel_name": "Diesel",
  "country": "ES",
  "date": "2025-06-15T00:00:00",
  "quantity": 50.0,
  "vehicle_license_plate": "1234-ABC",
  "toc_id": null,
  "unit_name": "liters",
  "status": "active",
  "created_at": "2025-06-15T10:30:00",
  "updated_at": "2025-06-15T10:30:00"
}
```

### Upsert Behavior

If a recharge with the same combination of `country`, `date`, `quantity`, and `vehicle_license_plate` already exists within the organization, the existing record is updated instead of creating a duplicate.

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

### 404 Not Found

**Cause:** The `fuel_id` does not exist or is inactive.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "code": "NOT_FOUND",
  "detail": "Fuel with id '550e8400-e29b-41d4-a716-446655440000' not found or inactive"
}
```

**Solution:** Use [`GET /logistics/fuels`](/api-reference/logistics/get-fuels) to get the full list of valid fuel IDs.

### 422 Validation Error

**Cause:** Missing required fields or invalid country code.

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "country"],
      "msg": "Not Valid Country Code, must be ISO 3166-1 alpha-2"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Create Recharges (Bulk)" icon="layer-group" href="/api-reference/logistics/create-recharges-bulk">
    Create up to 5,000 recharges in one request
  </Card>

  <Card title="List Recharges" icon="gas-pump" href="/api-reference/logistics/get-recharges">
    Retrieve fuel consumption records
  </Card>

  <Card title="Delete Recharge" icon="trash" href="/api-reference/logistics/delete-recharge">
    Delete a single recharge
  </Card>

  <Card title="Get Vehicle Types (TOCs)" icon="truck" href="/api-reference/logistics/get-tocs">
    List available vehicle types
  </Card>

  <Card title="List Fuel Types" icon="fire-flame-simple" href="/api-reference/logistics/get-fuels">
    List all available fuel types and their IDs
  </Card>
</CardGroup>
