Skip to main content
POST
← Purchases API Create one or many purchases of goods and services (Scope 3 category 1, or category 2 for capex). Say what was bought, from whom, when and for how much; Dcycle picks the emission factor and calculates the emissions in the background. The purchases are the ones /v1/purchases reads and edits. The request checks every record and writes them all at once, then answers 202 Accepted with an ingest job that classifies and calculates them (see how bulk ingestion works). Follow it with GET /v2/ingest-jobs/{id} or, for a job submitted with an API key, the ingest_job.finished webhook.
Beta. Part of the bulk ingest API, in beta. The contract may still change before general availability.

How it works

  1. Every record is checked. If any is invalid the whole request is rejected with 422 and nothing is written: rejected is the number of invalid records and errors lists them (up to 100).
  2. The purchases are written at once, with status in_progress, in the x-organization-id organization. A supplier sent by name is matched by its exact name (case, spaces and punctuation count; commas become dots) and country among the organization’s suppliers, or created: send one spelling per supplier, or its supplier_id.
  3. The job classifies and calculates them in the background, in chunks of 100 purchases grouped in the order sent. Within a chunk, the unclassified suppliers are ranked by the amount of their purchases, one entry per supplier (quantity converted to EUR; non_currency_quantity is not spend, so a supplier with only physical amounts ranks last, and a chunk with no monetary amount classifies nobody), and those that together make up 80 % of it are classified by their activity (SIC/CNAE code, from D&B); the rest start with a generic activity (code: "est.", code_type: "cnae_2009" in List Purchase Suppliers), which you correct in the Dcycle app. A new supplier whose name and country Dcycle already knows is linked to its known classification without a new lookup. Each purchase ends active or error. A description match below the confidence threshold, and a physical-unit match the matcher is not sure enough to apply without your confirmation, end active and count in the totals, with LOW_CONFIDENCE_PURCHASE_FACTOR_MATCH in their error_messages and needs_factor_review: true: confirm or change the factor in the Dcycle app. A purchase the free plan’s quota left on the supplier’s factor ends active with PURCHASE_DESCRIPTION_QUOTA_EXHAUSTED (see How the emission factor is chosen). A purchase in error has its job item failed with EXCHANGE_RATE_NOT_FOUND or CALCULATION_FAILED, and the reason in its error_messages (see Why a purchase failed).
  4. When every chunk is done the job is completed (or completed_with_errors). ingest_job.finished is sent only for jobs submitted with an API key, to the webhook endpoints of the organization in the request’s x-organization-id.

How the emission factor is chosen

Without matching_method the method comes from the record: description when it has one, else supplier, as for a purchase added in the Dcycle app, through POST /v1/purchases or in a bulk upload that picks no method. A description that does not identify the item on its own, such as an internal lot code, is read again with the supplier’s name and your organization’s name and sector. One that cannot be matched either way falls back to the supplier’s factor. With description, the match runs in the background and may finish after the job: such a purchase is calculated with the supplier’s factor first and recalculated when its match arrives. An organization on the free plan with no paying group above it has a lifetime quota of 500 description lines for description matching. It cannot send purchases through the API (403 PLAN_FEATURE_NOT_INCLUDED), so the quota applies to the purchases it creates in the Dcycle app. A subsidiary of a paying group, or a direct investee of a paying fund, has no quota. A line is a description with its supplier and country; purchases of one request that share it count once, and a line one of the organization’s purchases already holds a match for reuses it without counting. The quota counts lines sent to the matcher and is never refunded: a line sent again after its purchases were deleted counts again. Once it is spent, a purchase sent with description gets the supplier’s factor, as with supplier, and PURCHASE_DESCRIPTION_QUOTA_EXHAUSTED in its error_messages. One with only non_currency_quantity cannot be priced by the supplier’s factor (per euro): it fails with PURCHASE_CALCULATION_NO_TOTAL_IMPACTS_PRODUCED and that code (see Why a purchase failed). The code is set by the calculation that met the quota; a later recalculation with the purchase’s stored factor removes it. A custom_ef_record_id and a match already stored for the purchase are still used. A dry run does not check the quota.

Request

Headers

string
required
Your API key (see Authentication).
string
required
The organization the purchases belong to, and their suppliers: one of the organizations you can write to. A record cannot name another organization: send each organization’s purchases with its own x-organization-id. The job and its webhook belong to that organization, so register a webhook endpoint in each organization you submit as.
string
required
1 to 255 characters, one per batch, looked up per organization across every v2 bulk route. Within 24 hours, the same key with the same route and body returns the original job (with Idempotent-Replayed: true) instead of creating the purchases again; the same key with another body or on another route is 422 IDEMPOTENCY_KEY_REUSED, and while the first request is still being processed 409 IDEMPOTENCY_KEY_IN_PROGRESS. After 24 hours the key is free, and a request with it is a new one. See The Idempotency-Key.

Query Parameters

boolean
default:"false"
Check only: the same 422 for invalid records, nothing written, no job; 200 with {"dry_run": true, "submitted": n, "valid": n} when every record is valid. The Idempotency-Key header is still required, but a dry run does not check or store it.
boolean
default:"false"
Accept negative amounts (returns, credit notes). They subtract emissions, but the net never goes below zero. The net is taken per organization and expense_type (opex and capex apart), over all time, in emissions. When it would go below zero, returns are rejected, most negative first, until it is back at zero or above: each ends in error with PURCHASE_NET_NEGATIVE_EMISSIONS, and is calculated again on its own once there is room (new purchases calculated, or a return deleted). Before resending a failed item of a return, check the purchase’s status with Get Purchase: a return can be calculated later.

Body Parameters

array[object]
required
The purchases to create, 1 to 5,000. A field not listed here is rejected (SCHEMA_INVALID).

Response

202 Accepted with the job (entity_type: purchases, operation: create) and a Location header to it. To read the result:
  • GET /v2/ingest-jobs/{id}/items has one item per record, in the order sent. Its entity_id is the purchase’s id. A failed item carries its error_code.
  • List Purchases returns the purchases with their status and emissions (co2e), and Get Purchase why one is in error (error_messages).
If chunks_done stops moving, see A job that does not finish: never resend the batch with a new Idempotency-Key, because its purchases are already stored.

Why a purchase failed

A purchase in error has its job item failed: with EXCHANGE_RATE_NOT_FOUND (error_params.field is unit_id) when no exchange rate to euros was found for its currency on its date, as business travels and freight transports answer it, and with CALCULATION_FAILED otherwise. The exchange rate is checked first: a purchase sent again in euros may still fail with CALCULATION_FAILED. The reason is also in the purchase’s error_messages, read with Get Purchase:

Errors

Problem details. Per-record codes in errors[].error_code of a 422 BULK_RECORDS_REJECTED: Request-level errors: 401 for a missing or invalid API key, 403 LOGGED_USER_NOT_MEMBER when the key’s user is not a member of the organization, 422 REQUEST_VALIDATION_FAILED for a malformed body (no records, more than 5,000, no Idempotency-Key), 422 IDEMPOTENCY_KEY_REUSED, 409 IDEMPOTENCY_KEY_IN_PROGRESS, and 429 beyond the rate limits.

Limits

Delete Purchases (v2)

Delete purchases by id

List Purchase Suppliers

Ids for supplier_id

Get Ingest Job

Follow the calculation

List Job Items

The purchase id and outcome of each record

List Purchases

The purchases and their emissions

List Units

Currency and physical unit ids

Custom Emission Factors

Your own factors for custom_ef_record_id