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. Follow it with GET /v2/ingest-jobs/{id} or the ingest_job.finished webhook.
Beta. Part of the bulk ingest API, currently 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; the answer lists every invalid record, so you can fix them all at once.
  2. The purchases are written at once, with status in_progress, in the x-organization-id organization. A supplier sent by name is looked up among the organization’s suppliers (same name and country), or created.
  3. The job classifies and calculates them in the background, in chunks. A new supplier is classified by its activity (SIC/CNAE code, from D&B) when it carries most of the chunk’s spend; the rest get a generic activity. Each purchase ends active, in_review (calculated, with a description match below the confidence threshold) or error: its job item is then failed with CALCULATION_FAILED, e.g. when the supplier could not be classified or there is no exchange rate for the currency on that date.
  4. When every chunk is done the job is completed (or completed_with_errors) and ingest_job.finished is sent to your webhook endpoints.

How the emission factor is chosen

A description that cannot be matched 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.

Request

Headers

string
required
Your API key (see Authentication).
string
required
The organization the purchases belong to, and their suppliers. A record cannot name another organization: send each organization’s purchases with its own x-organization-id.
string
required
1 to 255 characters, unique per batch. A retry with the same key and body returns the original job instead of creating the purchases again; the same key with another body is 422 IDEMPOTENCY_KEY_REUSED, and while the first request is still being processed 409 IDEMPOTENCY_KEY_IN_PROGRESS.

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.
boolean
default:"false"
Accept negative amounts (returns, credit notes). They subtract emissions, never below zero for the organization’s purchases as a whole: a return the net cannot absorb ends in error.

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).

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

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