# Tutorial: Cancelling orders via "Order Cancellation"
After the buyer sends an order, the buyer may cancel the order if this is done before the order is prepared for delivery. This can be done with an Order Cancellation transaction via the POST /api/v1/{partyId}/purchaseOrder/{documentId}/cancel endpoint. The seller can either accept or reject the cancellation with the Order Response.
# Prerequisite
- An order is successfully sent, an
OrderSenttopic is provided. - The sent order uses the Advanced Ordering profile (opens new window)
- The seller supports the "Order Cancellation".
- Be able to Receive OrderResponse messages so the seller can accept or reject the cancellation.
# Step 1: Cancel the order
Cancel the order via the POST /api/v1/{partyId}/purchaseOrder/{documentId}/cancel endpoint and provide the reason for cancellation.
Order Cancellation example:
{
"cancellationNote": "The substituted items does not fit our usage."
}
# Step 2: Receive hooks
When the order cancellation is successfully received by the receiver access point a topic OrderCancellationSent will be broadcasted to your registered hooks.
The available topics are:
- OrderCancellationSent
- OrderCancellationSentError
- OrderCancellationSentRetry
# Step 3: Receive confirmation via Order Response
The seller can either accept or reject your cancellation. Once the order response message is received a hook with topic OrderResponseReceived will be sent.
Order Cancellation Accepted example
{
"topic": "OrderResponseReceived",
"partyId": "NL:KVK:RECEIVER",
"hookId": "111",
"documentId": "b34d7213-dd81-4a23-8867-99b12b4ca39e",
"refToDocumentId": "2a737b9e-a724-4153-8a86-4fb8f334db8b",
"message": "'OrderResponse' received. Status: 'Accept'.",
"details": {
"note": "Response message to accept cancellation of the order.",
"statusCode": "AP",
"status": "Accept",
"orderReferenceId": "Order-1",
"id": "Cancellation-1",
"protocol": "As4",
"returnedMessageId": "b34d7213-dd81-4a23-8867-99b12b4ca39e@econnect.eu",
"sender": "NL:KVK:SENDER",
"accessPoint": "C=NL, O=eConnect International B.V., OU=PEPPOL TEST AP, CN=PNL000052",
"documentTypeId": "urn:oasis:names:specification:ubl:schema:xsd:OrderResponse-2::OrderResponse##urn:fdc:peppol.eu:poacc:trns:order_response:3::2.1",
"profileId": "urn:fdc:peppol.eu:poacc:bis:advanced_ordering:3",
"receiver": "NL:KVK:RECEIVER",
"messageId": "5156bf0f-9bf7-4687-9ae7-a678c7931a9b@econnect.eu",
"refToMessageId": "2a737b9e-a724-4153-8a86-4fb8f334db8b@econnect.eu"
},
"createdOn": "2022-01-28T14:26:52.3980938+00:00",
"sentOn": "2022-01-28T14:26:52.6101319+00:00"
}