Skip to main content
PATCH
← Purchases API Give suppliers you already have their activity code (CNAE or SIC), which picks the spend-based emission factor of their purchases: the suppliers Create Purchases (v2) created in_progress from a supplier_name it did not know, the ones created in the app, or one Create Purchase Suppliers (v2) rejected with SUPPLIER_ALREADY_EXISTS. The request checks every record, gives each supplier its code at once and answers 202 Accepted with an ingest job that calculates their purchases again in the background (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: its supplier exists and is in your organization’s perimeter, it is not already in the request, and its code is an active code of its framework, as in Create Purchase Suppliers (v2). If any record is invalid the whole request is rejected with 422 and nothing is written (all or nothing).
  2. Every supplier takes its code at once, in one transaction: it is active, and a classification Dcycle had found for it (D&B) is replaced by yours, as the Data Importer’s supplier codes import does. A D&B lookup still running for the supplier, after Create Purchases (v2), does not overwrite your code when it ends, unless your code is the estimated one (est.), which D&B still replaces. Its name and country do not change.
  3. The job calculates the purchases of each supplier again, in the supplier’s own organization, with the factor of the new activity, whatever their status was (an error one included). Disabled purchases are left as they are. When its chunk starts, every enabled purchase of the chunk’s suppliers goes back to in_progress, without emissions, and takes its new emissions when its batch is calculated. A chunk holds up to 100 suppliers and up to 5,000 purchases between them; a supplier with more purchases gets a chunk of its own, which calculates them 5,000 at a time. A supplier sent with the code it already has is calculated again too, so send only the suppliers whose code you want to set or change.
  4. When every chunk is done the job is completed, or completed_with_errors when a supplier’s item failed (see Response). The purchases of a supplier whose item succeeded are calculated; with matching_method: "description", a purchase whose description match finishes later is calculated again then, as in Create Purchases (v2). For a job submitted with an API key, ingest_job.finished is sent with "operation": "update" to the webhook endpoints of the x-organization-id organization.

Request

Headers

string
required
Your API key (see Authentication).
string
required
The organization the suppliers are classified for. Its suppliers, and those of the organizations under it that you can write to (its perimeter), can be classified.
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); 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.

Body Parameters

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

Response

202 Accepted with the job (entity_type: purchase_suppliers, operation: update) and a Location header to it. GET /v2/ingest-jobs/{id}/items has one item per supplier, in the order sent, with the supplier’s id as entity_id. The supplier keeps its new code whatever its item says. An item is failed when some of the supplier’s purchases ended in error, and error_params.purchases_failed says how many:
  • EXCHANGE_RATE_NOT_FOUND when every one that failed did so for want of an exchange rate to euros for its currency on its date;
  • CALCULATION_FAILED otherwise: no emission factor for the activity in the supplier’s country, a return that would take the organization’s net emissions below zero…
List those purchases with List Purchases (supplier_id[] and status[]=error, with the supplier’s organization in x-organization-id); their error_messages say why, as in Why a purchase failed. The supplier’s other purchases are calculated. An item is also failed with CALCULATION_FAILED and error_params: null when the supplier was deleted before the job reached it, or when its calculation stopped on an unexpected error: then its purchases not calculated yet stay in_progress, without emissions. Send the supplier again with a new Idempotency-Key to calculate them.

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 1,000, no Idempotency-Key), 422 IDEMPOTENCY_KEY_REUSED, 409 IDEMPOTENCY_KEY_IN_PROGRESS, and 429 beyond the rate limits.

Limits

Create Purchase Suppliers (v2)

Create new suppliers, with their code

List Purchase Suppliers

Find the ids to classify

Create Purchases (v2)

Purchases from these suppliers

Get Ingest Job

Follow the recalculation