home > support > API > Marketplace API > cancel booking
Cancel a booking
Tour operators can cancel any bookings made in their account, Marketplace Agents can cancel bookings they have made in any account they are connected to.
Excludes temporary bookings, just delete those or let them expire.
Generally speaking with the TourCMS API you will be looking for an error node containing the text OK to determine success, note PREVIOUSLY CANCELLED here would also indicate a booking as being cancelled.
Endpoint | /c/booking/cancel |
Formats | XML |
Example | URL: /c/booking/cancel.xml POST data:
|
Verb | POST |
PHP examples use the PHP Client Library with SimpleXML
object cancel_booking ( SimpleXMLElement $booking_data, int $channel )
// Set the channel ID
$channel = 3930;
// Create a new SimpleXMLElement to hold the booking details
$booking = new SimpleXMLElement('<booking />');
// Must set the Booking ID on the XML, so TourCMS knows which to cancel
$booking->addChild('booking_id', '12345');
// Optionally add a note explaining why the booking is cancelled
$booking->addChild('note', 'Booking created accidentally');
// Call TourCMS API, cancelling the booking
$result = $tourcms->cancel_booking($booking, $channel);
// Check the result, will be "OK" if a booking was updated
if ($result->error == "OK") {
// Print a success message
print "Booking cancelled.";
} else if($result->error == "PREVIOUSLY CANCELLED" {
// Print a different success message
print "Booking has already been cancelled.";
} else {
// Some problem
print "Unable to cancel booking (" . $result->error . ").";
}
Booking deleted.
C# examples use the .Net Client Library
XmlDocument CancelBooking ( XmlDocument bookingData, int channelId )
// Set the ID for the channel this booking is made with
int channelId = 12345;
// Create an XMLDocument to hold the booking details
XmlDocument bookingData = new XmlDocument();
// Create the XML Declaration, append it to XML document
XmlDeclaration dec = bookingData.CreateXmlDeclaration("1.0", null, null);
bookingData.AppendChild(dec);
// Create the root element, append it to the XML document
XmlElement root = bookingData.CreateElement("booking");
bookingData.AppendChild(root);
// Must set the Booking ID so TourCMS knows which booking to update
XmlElement bookingId = bookingData.CreateElement("booking_id");
bookingId.InnerText = "12345";
root.AppendChild(bookingId);
// Optionally add a note explaining the reason for cancellation
XmlElement req = bookingData.CreateElement("note");
req.InnerText = "Booking created accidentally";
root.AppendChild(req);
// Query the TourCMS API.
XmlDocument response = myTourCMS.CancelBooking(bookingData, channelId);
// Check the status
// Will be "OK" if the booking was cancelled.
// "PREVIOUSLY CANCELLED" if it has been cancelled already.
string status = response.GetElementsByTagName("error")[0].InnerText;
if (status == "OK")
{
Console.WriteLine("Booking cancelled.");
}
else
{
Console.WriteLine("Error: " + status);
}
OK
VB examples use the .Net Client Library
XmlDocument CancelBooking ( XmlDocument bookingData, Integer channelId )
' Set the ID for the channel this booking is made with
Dim channelId As Integer = 3930
' Create an XMLDocument to hold the booking details
Dim bookingData As XmlDocument = new XmlDocument()
' Create the XML Declaration, append it to XML document
Dim dec As XmlDeclaration = bookingData.CreateXmlDeclaration("1.0", null, null)
bookingData.AppendChild(dec)
' Create the root element, append it to the XML document
Dim root As XmlElement = bookingData.CreateElement("booking")
bookingData.AppendChild(root)
' Must set the Booking ID so TourCMS knows which booking to cancel
Dim bookingId As XmlElement = bookingData.CreateElement("booking_id")
bookingId.InnerText = "12345"
root.AppendChild(bookingId)
' Optionally add a note
Dim req As XmlElement = bookingData.CreateElement("note")
req.InnerText = "Booking created accidentally"
root.AppendChild(req)
' Send the data to the TourCMS API, cancelling the Booking
Dim doc As XmlDocument = myTourCMS.CancelBooking(bookingIdData, channelId)
' Check the status
' Will be "OK" if the booking was updated
' "PREVIOUSLY CANCELLED" if it has been cancelled already
Dim status As String = doc.GetElementsByTagName("error")(0).InnerXml
If status = 'OK' Then
Console.WriteLine("Booking Cancelled.")
Else
Console.WriteLine("Error: " & status)
End If
OK
NodeJS examples use the NodeJS Wrapper
TourCMS.cancelBooking({
channelId: 3930,
booking: {
booking_id: 8451,
note: "Booked accidentally"
},
callback: function(response) {
console.log(response.error);
}
});
OK
Looking for sample code in a different language? TourCMS and community provided API libraries
Implementing yourself? Check the REST info for this endpoint.
Enter your TourCMS API credentials below to call the Cancel Booking endpoint.
Take care, submitting this form will modify live data!
The following fields can be posted as XML when calling the API, the booking_id is the only required field.
XML Node | Notes |
---|---|
booking_id | TourCMS ID for the booking to delete |
note | Optionally add a note explaining why the booking was cancelled |
cancel_reason | If not set, we will assume reason 22
1 - Cancelled by customer request, see notes |
suppress_email | Optional. Set to 1 to stop TourCMS sending a cancellation email. For use by Tour Operators only (not for use by Marketplace Partners. |
XML Node | Notes |
---|---|
request | Confirmation of the request that you sent |
error | Any error message returned, if there is no error this will just contain the text OK. If the booking is already cancelled - either via API or by a staff member in the back office - TourCMS will return a PREVIOUSLY CANCELLED error. You may wish to code for this, and handle the same as an "OK" response. |