Skip to main content
POST
/
v1
/
facilities
Create Facility
const options = {
  method: 'POST',
  headers: {
    'x-api-key': '<x-api-key>',
    'x-organization-id': '<x-organization-id>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: '<string>',
    type: '<string>',
    country: '<string>',
    address: '<string>',
    logistic_factor: 123,
    categories: {},
    cups_list: {}
  })
};

fetch('https://api.dcycle.io/v1/facilities', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

Create Facility

Create a new facility in your organization. The system will track energy consumption and calculate CO2e emissions for the facility.
Address or Country Required: You must provide either an address (from which the country is geocoded) or a country code. If both are provided, the geocoded country from the address takes precedence.

Request

Headers

x-api-key
string
required
Your API key for authentication
x-organization-id
string
required
Your organization UUID

Body Parameters

name
string
required
Name of the facilityExample: "Madrid Office"
type
string
required
Type of facilityExample: "office"
country
string
ISO 3166-1 country code. Required if address is not provided.Examples: "ES", "FR", "DE", "US"
address
string
Physical address of the facility. If provided, the country is automatically geocoded from the address.Example: "Calle Gran Vía 1, Madrid, Spain"
logistic_factor
number
default:"0.8"
Logistic factor for scope 2 calculation in logistics reports (0 to 1)Example: 0.8
categories
array[string]
Consumption categories enabled for this facilityAvailable values: heat, electricity, water, rechargeExample: ["heat", "electricity", "water"]
cups_list
array[string]
List of CUPS (electricity supply point) codesExample: ["ES0021000000000001AA"]

Response

Returns the created facility object with HTTP 201.

Example

curl -X POST "https://api.dcycle.io/v1/facilities" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Madrid Office",
    "type": "office",
    "country": "ES",
    "address": "Calle Gran Vía 1, Madrid",
    "logistic_factor": 0.8,
    "categories": ["heat", "electricity", "water"]
  }'

Successful Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Madrid Office",
  "type": "office",
  "country": "ES",
  "address": "Calle Gran Vía 1, Madrid",
  "status": "active",
  "co2e": null,
  "co2e_biomass": null,
  "logistic_factor": 0.8,
  "categories": ["heat", "electricity", "water"],
  "cups_list": null,
  "facility_purpose_type": "facilities",
  "created_at": "2024-11-24T10:30:00Z",
  "updated_at": "2024-11-24T10:30:00Z"
}

Common Errors

422 Validation Error

Cause: Neither address nor country provided
{
  "detail": "Either address or country is required."
}
Cause: Invalid address
{
  "detail": "Invalid address."
}