editable_fields on the order to see which fields you can change. Contact Bahn for changes outside these permissions.
Send a safe write
A change and a cancellation use the same procedure:1
Read the current order
Call
GET /v2/orders/{order_id}. Use this response, not a copy that you stored earlier.2
Check the action
For changes, check that every supplied field is in
editable_fields. For cancellation, check that allowed_actions contains cancel. Otherwise, show cancellation_unavailable_reason and stop.3
Send the current revision
Put the order
revision inside double quotation marks in the If-Match header.4
Send a new idempotency key
Create a new
Idempotency-Key for this decision. Store the key, the If-Match value, and the body before you send the request.5
Retry with the same values
After a timeout or a
5xx response, send the same key, If-Match value, and body again.6
Read again after a conflict
After
412 revision_conflict, read the order again and decide again. Use a new key for the new decision.If-Match value looks like this:
W/"...", or * returns 400 validation_error.
An idempotency key has 8 to 255 characters. Keys are shared by all V2 writes for your account, so a cancellation must not use the key of an earlier change. A retry of a completed write does not do the write again. It returns 200 with the current order, which can differ from the first response.
A live ETA change does not change the order revision. A driver booking, an unbooking, and a change of driver do change it.
Change an order
SendPATCH /v2/orders/{order_id} with a JSON Merge Patch body and the content type application/merge-patch+json.
Cancellation and primary delivery close all updates. A pending trade-in return does not reopen the primary vehicle’s contact fields.
allowed_actions contains update when at least one field can change. An assigned order can return:
null to clear the release code. A contact patch changes only its supplied name, phone, or email. Omitted contact fields stay unchanged. Required private-stop contact details cannot be cleared. Code/contact-only changes preserve the price and timing and work on pickup day without booking lead-time validation.
If any supplied field is locked, the API rejects the entire request with 409 order_not_updateable. The errors array names each locked field with path and code: "field_not_editable". No part of that request is saved. Read the order again and submit only permitted changes with a new idempotency key.
When you clear the pickup windows, keep
available_from so that pickup still has a start time. When you send items, include the VIN or registration number and every vehicle fact that you want to keep, including height_mm and tires. The CMR recipient cannot change after creation.
The winter-tire terms of an order stay as booked until you send items again. Then Bahn prices the new tire answer at the time of the change.
Changes to booking details must follow the same rules as a new order. Pickup and delivery times gives the time rules. A change to the route, vehicle, or service can calculate a new price.
This body replaces the requested delivery windows and keeps every other value:
BAHN_ORDER_ID to the order that you intend to change.
Cancel an order
SendDELETE /v2/orders/{order_id} with the current revision in If-Match and an idempotency key. The request has no body.
This example reads the order and cancels it only when the action is available. Set BAHN_ORDER_ID to the intended test order.
curl, jq, and uuidgen. Keep the key when you retry the same request.
A successful cancellation has these results:
- The order status becomes
cancelled. The order stays available for reads. allowed_actionscontains onlyget_files, andget_inspection_reportwhen the order uses thefullinspection service.- Location tracking ends.
- Bahn sends
com.bahn.order.cancelled.v1. - Bahn withdraws the open transport work for the order. If Bahn offered that work together with other orders, Bahn arranges transport for those orders separately. The cancellation response does not wait for this.
Handle a rejected write
400 validation_error: A header or the body is not valid. For example,If-Matchis not inside double quotation marks. Correct the request.403 permission_denied: The credential does not have theorders:writescope. Use a credential with that scope.409 order_not_cancellable: Cancellation is not available, anddetailcontains the reason. Read the order and showcancellation_unavailable_reason. Do not retry.409 order_not_updateable: One or more supplied fields are locked. Readerrorsfor the field paths andeditable_fieldson the current order. Submit permitted fields as a new decision with a new key.409 idempotency_conflict: The key belongs to a different request, or the first request with this key is still in progress. Compare with your stored request. If the first request is still in progress, wait and retry the same request.412 revision_conflict: The order changed after you read it. Read the order again, and decide again with a new key.422 business_rule_violation: The changed values break a transport rule, anddetailexplains which one. Correct the values. Only a change returns this code.
409 even when the revision is out of date. Cancellation checks its action before the revision.
A driver can book the order while your request is in progress. A cancellation then returns 409 order_not_cancellable. A change can return 412 revision_conflict. Read the order again and check editable_fields. Pickup codes and contacts can remain editable.
Read Errors, retries, and conflicts for authentication, size, and server errors.