Purchase Order Batch API Guide
Use the POST /organizations/{organizationId}/purchase-orders/batch endpoint to create or update purchase order activities. Choose an importType and send the purchase orders in the activities array.
Before you start
You need your Carbon Trail organization ID and an API key. Create an API key in the Carbon Trail Portal and send it in the Authorization header. See Authentication for details.
export BASE_URL="https://api.carbontrail.net/partner/v1.0"
export ORGANIZATION_ID="YOUR_ORGANIZATION_ID"
export CARBON_TRAIL_API_KEY="ctk_v1_xxx"
Work with purchase order activities
Choose one of these importType values, including the capitalization shown:
importType | What it does |
|---|---|
Create | Create new activities. |
Create And Update | Create new activities and update existing activities in the same batch. |
Update | Update existing activities. |
Each request uses the same activities array. For example, to create a purchase order activity:
{
"importType": "Create",
"activities": [
{
"category": "Purchased Goods",
"id": "po-line-005",
"purchasedOrderNumber": "PO-005",
"sku": "ABC-001-BLK-XXL",
"amount": 50,
"unit": "Unit"
}
]
}
To create po-line-005 and update an existing po-line-003 in one batch, use Create And Update:
{
"importType": "Create And Update",
"updateMode": "Patch",
"activities": [
{
"category": "Purchased Goods",
"id": "po-line-005",
"purchasedOrderNumber": "PO-005",
"amount": 50,
"unit": "Unit"
},
{
"category": "Purchased Goods",
"id": "po-line-003",
"purchasedOrderNumber": "PO-003",
"amount": 150,
"unit": "Unit"
}
]
}
To update existing activities only, use Update with the activities to update in activities:
{
"importType": "Update",
"updateMode": "Patch",
"activities": [
{
"category": "Purchased Goods",
"id": "po-line-003",
"purchasedOrderNumber": "PO-003",
"amount": 150,
"unit": "Unit"
}
]
}
How existing activities are identified
An activity in the request is considered existing if its id or an externalIds value matches an activity already in the organization. Purchase order lines can also match by purchasedOrderNumber (the PO number) together with either sku or articleNumber. Within the same PO, a nonempty sku matching an existing line's SKU or a nonempty articleNumber matching its article number identifies an existing activity. If multiple products in that PO have a matching SKU or article number, all of them are updated. These matches determine which activities are updated in Create And Update or Update batches.
Set the update mode
Set updateMode to Patch when importType is Create And Update or Update. The field is required for these import types, and Patch is the only supported update mode today. Replace update mode will be supported in the future. updateMode is not required for Create.
Check the batch result
The endpoint returns HTTP 202 Accepted and a batchId when the batch is accepted for processing. Acceptance does not confirm that every activity succeeded. An illustrative initial response is:
{
"batchId": "example-batch-id",
"status": "Accepted",
"totalRecords": 2
}
Use the returned ID with the GET /organizations/{organizationId}/activities/batch/{batchId} endpoint:
curl --request GET \
"$BASE_URL/organizations/$ORGANIZATION_ID/activities/batch/example-batch-id" \
--header "Authorization: ApiKey $CARBON_TRAIL_API_KEY" \
--header "Accept: application/json"
The status response includes processing counts and an errors array for failed activities. recordIndex in an error is zero based, so 1 refers to the second activity in the request. Inspect the returned message and code for failure details.
Handle emissions when updating existing activities
The following rules apply only when an existing activity is updated, whether the request uses Create And Update or Update. They do not apply to activities created by Create or Create And Update.
For an update, the API handles each activity according to its existing state and whether that activity includes an emissions array in the request:
| Existing state | emissions in payload | Result |
|---|---|---|
Submitted | Omitted | Update the activity. Leave its existing emissions unchanged. |
Submitted | Supplied | Reject this activity and report it in the batch job's errors array. |
Unmapped or Mapped | Supplied | Delete the activity's existing emissions, then save the supplied emissions. |
Unmapped or Mapped | Omitted | Delete the activity's existing emissions, then calculate emissions for the updated activity. |
These rules are applied per updated activity. A submitted activity with supplied emissions can fail while other activities in the same batch are processed.
Submit an update batch
The following request illustrates all four cases. Assume the existing states are Submitted for the first two activities, Mapped for the third, and Unmapped for the fourth. The state is read from the existing activity; it is not included in this request.
curl --request POST \
"$BASE_URL/organizations/$ORGANIZATION_ID/purchase-orders/batch" \
--header "Authorization: ApiKey $CARBON_TRAIL_API_KEY" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{
"importType": "Update",
"updateMode": "Patch",
"activities": [
{
"category": "Purchased Goods",
"id": "po-line-001",
"purchasedOrderNumber": "PO-001",
"sku": "ABC-001-BLK-M",
"amount": 100,
"unit": "Unit"
},
{
"category": "Purchased Goods",
"id": "po-line-002",
"purchasedOrderNumber": "PO-002",
"sku": "ABC-001-BLK-L",
"amount": 200,
"unit": "Unit",
"emissions": [
{
"id": "emission-po-line-002",
"created": "2026-10-01T10:00:00Z",
"emissions": 120,
"activityId": "po-line-002",
"activityCategory": "Purchased Goods",
"activityKind": "Regular",
"source": "Real Data",
"emissionFactorType": "Custom",
"emissionScope": "Scope 3",
"scope3Category": "3.1 Purchased Goods and services",
"emissionFactorName": "Supplier-specific factor",
"emissionFactorValue": {
"value": 0.6,
"unit": "kg CO2e/Unit"
}
}
]
},
{
"category": "Purchased Goods",
"id": "po-line-003",
"purchasedOrderNumber": "PO-003",
"sku": "ABC-001-BLK-XL",
"amount": 150,
"unit": "Unit",
"emissions": [
{
"id": "emission-po-line-003",
"created": "2026-10-01T10:00:00Z",
"emissions": 90,
"activityId": "po-line-003",
"activityCategory": "Purchased Goods",
"activityKind": "Regular",
"source": "Real Data",
"emissionFactorType": "Custom",
"emissionScope": "Scope 3",
"scope3Category": "3.1 Purchased Goods and services",
"emissionFactorName": "Supplier-specific factor",
"emissionFactorValue": {
"value": 0.6,
"unit": "kg CO2e/Unit"
}
}
]
},
{
"category": "Purchased Goods",
"id": "po-line-004",
"purchasedOrderNumber": "PO-004",
"sku": "ABC-001-BLK-S",
"amount": 75,
"unit": "Unit"
}
]
}'
With the assumed existing states, po-line-001 is updated without changing its emissions. po-line-002 fails because it is submitted and supplies emissions. For po-line-003, the existing emissions are deleted and the supplied 90 kg CO₂e entry is saved. For po-line-004, the existing emissions are deleted and emissions are calculated from the updated activity.
Omit emissions to use the no-emission behavior in the table. The examples do not use an empty array to express omission.
Supply emissions in a mixed batch
To supply emissions for an existing activity in a Create And Update batch, include its emissions array:
{
"importType": "Create And Update",
"updateMode": "Patch",
"activities": [
{
"category": "Purchased Goods",
"id": "po-line-005",
"purchasedOrderNumber": "PO-005",
"amount": 50,
"unit": "Unit"
},
{
"category": "Purchased Goods",
"id": "po-line-003",
"purchasedOrderNumber": "PO-003",
"amount": 150,
"unit": "Unit",
"emissions": [
{
"id": "emission-po-line-003",
"created": "2026-10-01T10:00:00Z",
"emissions": 90,
"activityId": "po-line-003",
"activityCategory": "Purchased Goods",
"activityKind": "Regular",
"source": "Real Data",
"emissionFactorType": "Custom",
"emissionScope": "Scope 3",
"scope3Category": "3.1 Purchased Goods and services",
"emissionFactorName": "Supplier-specific factor",
"emissionFactorValue": {
"value": 0.6,
"unit": "kg CO2e/Unit"
}
}
]
}
]
}
Assuming po-line-005 is new and po-line-003 already exists in the Mapped state, the first activity is created. The second is updated: its existing emissions are deleted and the supplied entry is saved. The update rules in the table apply to existing activities in a Create And Update batch; they do not determine how emissions are handled for newly created activities.
Check emissions-related failures
For the four-activity Update example above, a completed job could report:
{
"batchId": "example-batch-id",
"status": "CompletedWithErrors",
"totalRecords": 4,
"processedRecords": 4,
"updatedRecords": 3,
"failedRecords": 1,
"errors": [
{
"recordIndex": 1,
"message": "Cannot add emissions to an activity in submitted state."
}
]
}
The error message is illustrative; inspect the returned message and code for the actual failure details.