201 Created), or answers 202 Accepted with an ingest job that calculates (or deletes) the records in
the background, and you follow that job until it finishes.
Synchronous and asynchronous routes
A route is asynchronous when its records need work after the request: calculating their emissions, or deleting them with everything that depends on them. It answers202 Accepted with the job, and its Location header is
/v2/ingest-jobs/{id}. The job processes the records in chunks; see Following a job.
A route is synchronous when its records need nothing calculated. It answers 201 Created with the created
resources, in submission order, each with its source_row_index and client_row_id. It also records a job, born
completed with 0 of 0 chunks, which sends no webhook: List Ingest Jobs shows it,
and its items map each record to the resource created (or, for a record that
matched an existing employee with on_existing=reuse, to that employee, in the reuse stage).
The last column says what a create or update route does with a record it already has, sent again in a request with
another Idempotency-Key (or the same key after 24 hours), as in a nightly job that resends
the whole month:
- Duplicated: the record is written a second time, and counts twice.
- Rejected: the whole request is
422 BULK_RECORDS_REJECTEDand nothing is written; each record that is already stored carries the code shown. Leave those records out, or delete them first to replace them. - Merged: the stored record is updated with what you send, as its route’s page explains.
- Replaced: the stored record takes what you send, the fields you leave out included, and is calculated again.
A request over its route’s limit is
422 REQUEST_VALIDATION_FAILED: split a bigger batch into several requests, each
with its own Idempotency-Key. Everything else on this page applies to both kinds of route.
All or nothing
Every record is checked before anything is written: first against the route’s schema, then against the rules that need your data (the ids it references exist and are in the perimeter, the unit fits, periods do not overlap…). If one record is invalid, the whole request is rejected with422 BULK_RECORDS_REJECTED and nothing is
written. Every record is still checked, so one answer lists them all: rejected is the number of invalid records and
errors lists them (up to 100), in submission order. The checks that weigh records against each other run once every
record passes the rest (the credit-note net of invoices, the contract and remuneration overlaps of own workforce), so
a second 422 can follow a first one you fixed. Each entry has:
source_row_index: the position of the record inrecords(or of the id inids), starting at 0.client_row_id: theclient_row_idyou sent with the record, ornull(alwaysnullin a delete).error_code: what is wrong, e.g.SCHEMA_INVALIDorREFERENCE_NOT_FOUND.error_params: the values that explain it, e.g.{"field": "facility_id", "value": "…"}.
Idempotency-Key
included, so you can resend with the same key or a new one. The codes every route shares are in
Errors; each route’s page lists its own.
Dry run
Add?dry_run=true to any of these routes to run the record checks and answer without writing anything. A valid batch
answers 200 OK with {"dry_run": true, "submitted": 2, "valid": 2}; an invalid one gets the same
422 BULK_RECORDS_REJECTED as the real request. No job is created.
The Idempotency-Key header is still required, but a dry run does not check or store it: a key used in the last 24
hours with another body or on another route passes the dry run and can still be rejected on the real request
(422 IDEMPOTENCY_KEY_REUSED). Generate the batch’s key once and send it with both.
A successful dry run means the records are valid, not that every one will calculate: on an asynchronous route the
calculation runs after the real request, and the job’s items give each record’s outcome.
The Idempotency-Key
Every bulk route requires anIdempotency-Key header (1 to 255 characters). Use one new key per batch, e.g. a UUID,
and send it again only to retry that same batch:
- Keys are looked up per organization (the one in
x-organization-id), across every v2 bulk route. - Within 24 hours, the same key with the same route and body returns the original answer instead of writing again,
with the header
Idempotent-Replayed: true: the same job, in its current state, on an asynchronous route; the same created resources on a synchronous one. - The same key with another body, or on another route, is
422 IDEMPOTENCY_KEY_REUSED. - While the first request with the key is in progress, a second one is
409 IDEMPOTENCY_KEY_IN_PROGRESS: retry with the same key and body afterRetry-Afterseconds, and you get the answer of the request that went through. - After 24 hours the key is free: a request with it is a new one, and each record is duplicated, rejected, merged or replaced as the route’s row in the table above says.
1200 or 1200.0) do not make
it another body. Any other change does, including a record added, removed or moved.
For example, with the key K:
Copy of each request: kept 90 days
Dcycle keeps a copy of every accepted request (the body as received, its route, itsIdempotency-Key and the key or
user that sent it) to investigate a job with you or to replay it if you ask. A rejected request or a dry run is not
kept. The copy is deleted 90 days after the request was accepted; deleting the organization deletes it sooner.
The job, its items and the records it wrote are not affected: Get Ingest Job and
List Ingest Job Items answer as before. Past 90 days Dcycle can no longer
replay or inspect the original request, so keep your own copy of what you send for as long as you need it.
Activity dates
An activity date is when something happened: a purchase, a trip, a shipment, the period of an invoice. Send it asYYYY-MM-DD, from 1970 (or the year each page gives) to tomorrow in UTC. Tomorrow is accepted so that a day
already under way in a time zone ahead of UTC (Asia-Pacific) fits. A later date rejects its record with
SCHEMA_INVALID: error_params.errors names the field with the type date_in_the_future
(activity_date_out_of_range past next year, on the dates that also stop at next year). Each create page links here the dates that follow this rule; the end of
a commuting period or of a vehicle consumption has its own range.
Amounts of money
Some routes take an amount of money with its currency. An amount that prices the record (a spend, or a quantity in euros) is below 10^12 in absolute value, as any other number. Atotal_spend is only kept with the record and stays
below 10^15, so a spend in a weak currency (VND, IDR) fits. The
currency is a unit of type fiat_currency from List Units. The names differ by route:
When a record is calculated from its amount and the rate of its currency to EUR cannot be had for its date, the job
item fails with
EXCHANGE_RATE_NOT_FOUND, and error_params.field names the currency field.
What the free plan includes
An organization on the free plan, with no paying group above it, can create and delete facilities, vehicles, vehicle consumptions and electricity, fuel and refrigerant invoices; upload files, read them and open their import sessions (each up to the plan’s limits); read its ingest jobs; and list, open and delete its webhook endpoints and read their deliveries. Every other v2 route answers403 PLAN_FEATURE_NOT_INCLUDED, a dry run included:
- purchases and suppliers, wastes, business travels, hotel stays, freight transports, employees and their commuting, sold products and their use, logistics requests and logistic hubs;
- own workforce employees, trainings and absences, and waste water treatments;
- water, district heating, district cooling and process invoices;
- creating, changing, testing and retrying webhook endpoints, and rotating their secret.
Perimeter
A record is written to the organization inx-organization-id, unless the route lets it point to another
organization of the perimeter: a waste or an invoice goes to the organization of its facility, a vehicle consumption to
its vehicle’s, a training, an absence or a commuting period to its employee’s, a waste water treatment measurement to
its plant’s (the facility in facility_id), a use of a sold product to the organization of the product its
period_id belongs to, and a facility to its organization_id (deprecated: send it in x-organization-id). The ids
a bulk delete takes must be in the perimeter too, and so must the supplier_id of
PATCH /v2/purchases/suppliers: a supplier stays in its
organization, and only its purchases there are calculated again.
The perimeter is the organization in x-organization-id and, recursively, the organizations below it. An organization
below is included when:
- its link to its parent organization is accepted and enabled,
- it is enabled itself (a disabled organization is left out, and so is everything below it), and
- its parent is not a group fund. A group fund is part of the perimeter, but the organizations below it are not, so the perimeter of a fund is the fund alone.
REFERENCE_NOT_FOUND for an id a record references, NOT_FOUND for an id to delete, and ORGANIZATION_NOT_FOUND for
the organization_id of a facility.
Following a job
GET /v2/ingest-jobs/{id} returns the job:
failed is reserved: treat every status other than processing as finished.
- Progress:
chunks_done / chunks_total.countshas the recordssubmitted,succeededandfailedso far. - End:
finished_atis when the last chunk finished (nullwhile the job isprocessing). - Per record: List Ingest Job Items returns one item per record, in
submission order, with its
source_row_index,client_row_id, theentity_idcreated (or deleted) and itsstatus(pending,succeeded,failed). A failed item says why inerror_code:CALCULATION_FAILED: the record is stored, but its emissions could not be calculated. It does not hold the other records: they are calculated and the job finishes.DELETE_FAILED: in a delete job, the entity was already gone when its chunk ran, or it could not be deleted. Check whether it still exists; if it does, send its id in a new delete job, and if that fails too, contact support with the jobid. A vehicle or a facility is hidden as soon as its delete is accepted, so a new delete job cannot reach it: contact support with the jobid.JOB_TIMED_OUT: the job made no progress for 4 hours and was closed with this record still pending (see A job that does not finish). In a create job the record is stored without emissions; in a delete job it was not deleted; in an update job the change is stored but its emissions were not calculated again.- In Classify Purchase Suppliers, the supplier keeps its
new code and the item says that some of its purchases ended in
error(CALCULATION_FAILEDorEXCHANGE_RATE_NOT_FOUND, with how many inerror_params.purchases_failed;CALCULATION_FAILEDwitherror_params: nullis a supplier deleted before its chunk ran, or a calculation that stopped on an error). - A route may give the reason with codes of its own instead: logistics legs (Why a leg failed to calculate), purchases (Why a purchase failed), business travels (How it works), freight transports (How it works) and commuting responses (How it works).
- Poll Get Ingest Job every 5 to 10 seconds until
statusis no longerprocessing, or - Receive the
ingest_job.finishedwebhook, which carries the same job object. It is sent only for jobs submitted with an API key (source: api_bulk), to the webhook endpoints of the organization in the request’sx-organization-id, once the last chunk finishes.
chunks_done normally moves within minutes. If it stops for 4 hours, the job is closed with its pending records
failed (JOB_TIMED_OUT) and still sends its webhook: see
A job that does not finish.
Testing an integration
Test the integration on your organization in Dcycle, the one it will send its data to. Create its key from a member of only the organizations the integration should reach (see Perimeter) and keep it in a secret manager from the first test.- Validate without writing. Send your batches with
?dry_run=trueuntil every one answers200. Nothing is written and no job is created, so you can repeat it as often as you need. - Send a small real batch, a few records, and follow its job until it finishes. Give each
record a single facility (
[{facility_id, percentage: 1}]in wastes and invoices), so each one is a single entity. Check the records and their emissions in the Dcycle app, and keep theentity_idof every item of that job: the job your request returned (itsLocation), never another job of the list. - Delete the test records by id with the delete route of the same resource in
the table above: for wastes,
POST /v2/wastes/delete; for logistics requests,POST /v2/logistics/requests/delete. A delete is permanent: send it with?dry_run=truefirst and check thatsubmittedis the number of test records. Until you delete them, the test records count in your organization’s footprint like any other record. - Test your webhook endpoint with Send Test Event: it sends a signed
webhook.testevent and writes no footprint data. The test batch and its delete also sendingest_job.finishedto every endpoint registered in the organization.
The same data in each route
Some data has a different field name in each route: map your columns with this table.Entity types
A job’sentity_type says what it creates, updates or deletes. Use these values in the entity_type filter of
List Ingest Jobs; the filter accepts any text, and a value that is not one of these
returns an empty page. The routes of each value are in the table above.
Related Endpoints
Get Ingest Job
Status and progress of one job
List Ingest Jobs
The jobs of your organization, newest first
List Ingest Job Items
Per-record outcomes of a job
Webhooks
Get
ingest_job.finished instead of polling