Skip to main content
POST
Create Invoice

Create Invoice

Create a new consumption invoice (electricity, heat, water, etc.) for your organization. This endpoint supports both single-facility invoices and distributed invoices (split across multiple facilities with percentage allocation).
This endpoint automatically calculates CO2e emissions based on the invoice type, quantity, and location. For distributed invoices, emissions are proportionally allocated across facilities.

Request

Headers

string
required
Your API key for authenticationExample: sk_live_1234567890abcdef
string
required
Your organization UUIDExample: ff4adcc7-8172-45fe-9cf1-e90a6de53aa9

Body Parameters

string
required
Type of consumption invoiceValid values: electricity, heat, water, recharge, processExample: "electricity"
number
required
Consumption quantity in the specified unitExample: 15000.5
string
required
UUID of the unit of measurementCommon units:
  • Electricity: kilowatt_hour_(kwh)
  • Natural gas: cubic_meter_(m³)
  • Water: cubic_meter_(m³)
  • Diesel/Gasoline: liter_(l)
Example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
string
required
Invoice period start date (ISO 8601 format)Example: "2024-11-01"
string
required
Invoice period end date (ISO 8601 format)Example: "2024-11-30"
string
required
UUID of the user creating the invoiceExample: "b2c3d4e5-f6g7-8901-bcde-fg2345678901"
array
required
Array of facility allocation objects. Sum of percentages must equal 1.0 (100%)

Facility Percentage Object:

  • organization_id (string, UUID, required) - Organization that owns the facility
  • facility_id (string, UUID, required) - Facility to allocate to
  • percentage (number, required) - Allocation percentage (0.0-1.0)
  • company_name (string, optional) - Company name for reference
  • facility_name (string, optional) - Facility name for reference
Example:
For distributed invoices (multiple facilities):
string
deprecated
Deprecated: Use facility_percentages insteadLegacy single facility ID field. Maintained for backwards compatibility.
string
External invoice reference number (e.g., supplier invoice number)Example: "INV-2024-11-001"
string
UUID of the energy/utility supplierExample: "f6g7h8i9-j0k1-2345-fghi-jk6789012345"
string
UUID of the facility fuel type (for heat invoices)Required for type: "heat" invoicesExample: "g7h8i9j0-k1l2-3456-ghij-kl7890123456"
string
CUPS code for Spanish electricity metersFormat: ES + 20 digits + 2 letters (e.g., ES0031406398765432GH0F)Example: "ES0031406398765432GH0F"
string
URL to the invoice file (PDF, image, etc.) stored in S3Example: "https://s3.amazonaws.com/dcycle-files/invoices/..."
string
UUID of custom emission factor group (if using custom factors)Example: "h8i9j0k1-l2m3-4567-hijk-lm8901234567"
string
Transport operation category (for logistics-related invoices)Example: "van_diesel"

Response

The create endpoint returns a lightweight confirmation with the core invoice fields. Use GET /v1/invoices/ for the full detail view.
string
UUID of the created invoice
string
Invoice type: electricity, heat, water, recharge, or process
string
Invoice status: loading (processing), active (complete), or error (failed)
string | null
UUID of the primary facility
string | null
UUID of the user who created the invoice
string | null
UUID of the energy supplier, if specified
string | null
External invoice reference number
string | null
CUPS code, if specified
boolean | null
Whether the invoice is enabled for emission calculations
boolean | null
Whether this is a self-consumption invoice (electricity only)

Example

Successful Response

Common Errors

401 Unauthorized

Cause: Missing or invalid API key

403 Forbidden

Cause: The user is not a member of the organization, or lacks permission to create invoices for it

400 Bad Request - Invalid Total Percentage

Cause: Sum of facility_percentages does not equal 1.0
Solution: Ensure the sum of all percentage values in facility_percentages equals exactly 1.0 (100%).

400 Bad Request - Invalid Invoice Type

Cause: Unsupported invoice type
Solution: Use only valid invoice types: heat, electricity, water, recharge, process

400 Bad Request - Invalid Facility

Cause: Facility doesn’t belong to the specified organization or is archived
Solution: Verify that:
  1. The facility_id exists and belongs to the organization_id
  2. The facility is not archived
  3. You have access to the organization

404 Not Found - Organization Not Found

Cause: Organization ID in facility_percentages doesn’t exist
Solution: Use valid organization UUIDs that exist in the system.

Use Cases

Single Facility Electricity Invoice

Create an electricity invoice for one facility:

Distributed Heat Invoice

Split a shared heating bill across multiple facilities:

Corporate Distribution

Headquarters distributing utility bills to subsidiaries:

Batch Invoice Creation

Create multiple invoices efficiently:

Special Notes

Invoice Status Workflow

Invoices go through the following status workflow:
  1. loading: Initial state after creation. System is calculating emissions.
  2. active: Processing complete. Emissions calculated and available.
  3. error: Processing failed. Check error_messages field in GET response.
Typically, invoices move from loading to active within a few seconds.

Distributed Invoices

When creating distributed invoices (multiple facilities):
  • The system creates one parent invoice + N child invoices (one per facility)
  • The parent invoice ID is returned in the response
  • All child invoices reference the parent via source_invoice_id
  • Emissions are automatically calculated proportionally for each facility
  • Percentages must sum to exactly 1.0 (100%)
Use cases for distributed invoices:
  • Shared utility bills across office floors
  • Corporate headquarters allocating costs
  • Multi-tenant buildings
  • Franchise operations with centralized billing

Date Format

Dates must be provided in ISO 8601 format: YYYY-MM-DD Valid examples:
  • "2024-11-01"
  • "2024-12-31"
The system will handle timezone conversion based on facility location.

Invoice Types and Required Fields

Different invoice types have different requirements:

Units

Common unit UUIDs for different consumption types:
  • Electricity: kilowatt_hour_(kwh)
  • Natural Gas: cubic_meter_(m³)
  • Diesel/Gasoline: liter_(l)
  • Water: cubic_meter_(m³)
Use the Units endpoint to get the complete list of available units and their UUIDs.

CUPS Validation

For Spanish electricity invoices, if you provide a cups code:
  • Format: ES + 20 digits + 2 letters
  • Example: ES0031406398765432GH0F
  • The system validates format but doesn’t verify existence with utility companies

Emission Calculation

CO2e emissions are calculated automatically based on:
  1. Consumption quantity and unit
  2. Facility location (country-specific emission factors)
  3. Time period (emission factors vary by year/month)
  4. Supplier (if renewable energy contract)
  5. Custom emission factors (if specified)
For electricity, the system calculates:
  • Scope 2 (consumption) emissions
  • Scope 3 (generation + T&D) emissions

File Attachments

To attach invoice files (PDF, images):
  1. Upload file to S3 using presigned URL (separate endpoint)
  2. Include the S3 URL in file_url field
  3. System will retain file for audit trail

List Invoices

Query created invoices

List Facilities

Get facility IDs for invoice creation

Authentication

Learn about API authentication