Delete Customer
curl --request DELETE \
--url https://your-site.com/wp-json/latepoint-api/v1/customers/{id} \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://your-site.com/wp-json/latepoint-api/v1/customers/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://your-site.com/wp-json/latepoint-api/v1/customers/{id}")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-site.com/wp-json/latepoint-api/v1/customers/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"data": {
"deleted_customer_id": 123,
"deleted_at": "<string>"
}
}Customers
Delete Customer
Delete a customer from the system
DELETE
/
wp-json
/
latepoint-api
/
v1
/
customers
/
{id}
Delete Customer
curl --request DELETE \
--url https://your-site.com/wp-json/latepoint-api/v1/customers/{id} \
--header 'X-API-Key: <x-api-key>'import requests
url = "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}"
headers = {"X-API-Key": "<x-api-key>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {'X-API-Key': '<x-api-key>'}};
fetch('https://your-site.com/wp-json/latepoint-api/v1/customers/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"X-API-Key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://your-site.com/wp-json/latepoint-api/v1/customers/{id}"
req, _ := http.NewRequest("DELETE", url, nil)
req.Header.Add("X-API-Key", "<x-api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.delete("https://your-site.com/wp-json/latepoint-api/v1/customers/{id}")
.header("X-API-Key", "<x-api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-site.com/wp-json/latepoint-api/v1/customers/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["X-API-Key"] = '<x-api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"data": {
"deleted_customer_id": 123,
"deleted_at": "<string>"
}
}Description
This endpoint allows you to delete a customer from the LatePoint system. The customer will be permanently removed from the database along with their associated data.Important: Deleting a customer is irreversible. Make sure you want to permanently remove this customer and all their associated data before proceeding.
Booking Protection: Customers with existing bookings cannot be deleted to maintain data integrity. You must first cancel or delete all associated bookings before deleting the customer.
Authentication
string
required
Your LatePoint API Key with delete permissions
Path Parameters
integer
required
Unique ID of the customer to delete
Response
boolean
Indicates if the deletion was successful
string
Success or error message
object
Examples
Delete Customer
curl -X DELETE "https://your-site.com/wp-json/latepoint-api/v1/customers/123" \
-H "X-API-Key: your_api_key_here"
Response Examples
Successful Deletion
{
"success": true,
"message": "Customer deleted successfully",
"data": {
"deleted_customer_id": 123,
"deleted_at": "2024-01-15 14:30:25"
}
}
Customer Not Found
{
"code": "customer_not_found",
"message": "Customer not found",
"data": {
"status": 404
}
}
Customer Has Bookings
{
"code": "customer_has_bookings",
"message": "Cannot delete customer with existing bookings",
"data": {
"status": 400,
"booking_count": 3
}
}
Deletion Failed
{
"code": "customer_delete_failed",
"message": "Error deleting customer: Database error",
"data": {
"status": 500
}
}
Error Codes
| Code | Status | Description |
|---|---|---|
customer_not_found | 404 | Customer with specified ID doesn’t exist |
customer_has_bookings | 400 | Customer has existing bookings and cannot be deleted |
customer_delete_failed | 500 | Database error or deletion failed |
latepoint_not_available | 503 | LatePoint plugin not loaded |
server_error | 500 | Internal server error |
JavaScript Example
// Delete customer function
async function deleteCustomer(customerId) {
try {
const response = await fetch(`https://your-site.com/wp-json/latepoint-api/v1/customers/${customerId}`, {
method: 'DELETE',
headers: {
'X-API-Key': 'your_api_key_here'
}
});
const result = await response.json();
if (result.success) {
console.log('Customer deleted successfully:', result.data);
return result.data;
} else {
throw new Error(result.message);
}
} catch (error) {
console.error('Error deleting customer:', error);
throw error;
}
}
// Usage with confirmation
async function deleteCustomerWithConfirmation(customerId) {
const confirmed = confirm('Are you sure you want to delete this customer? This action cannot be undone.');
if (confirmed) {
try {
const result = await deleteCustomer(customerId);
alert('Customer deleted successfully!');
return result;
} catch (error) {
if (error.message.includes('existing bookings')) {
alert('Cannot delete customer: They have existing bookings. Please cancel or delete all bookings first.');
} else {
alert('Error deleting customer: ' + error.message);
}
throw error;
}
}
}
// Delete customer with ID 123
deleteCustomerWithConfirmation(123);
PHP Example
<?php
// Delete customer using WordPress HTTP API
function delete_customer($customer_id) {
$url = 'https://your-site.com/wp-json/latepoint-api/v1/customers/' . $customer_id;
$response = wp_remote_request($url, array(
'method' => 'DELETE',
'headers' => array(
'X-API-Key' => 'your_api_key_here'
)
));
if (is_wp_error($response)) {
throw new Exception('Request failed: ' . $response->get_error_message());
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (!$data['success']) {
throw new Exception('Deletion failed: ' . $data['message']);
}
return $data['data'];
}
// Safe deletion with booking check
function safe_delete_customer($customer_id) {
try {
// First, check if customer has bookings
$bookings_url = 'https://your-site.com/wp-json/latepoint-api/v1/bookings?customer_id=' . $customer_id;
$bookings_response = wp_remote_get($bookings_url, array(
'headers' => array(
'X-API-Key' => 'your_api_key_here'
)
));
if (!is_wp_error($bookings_response)) {
$bookings_data = json_decode(wp_remote_retrieve_body($bookings_response), true);
if (!empty($bookings_data['data']) && count($bookings_data['data']) > 0) {
throw new Exception('Customer has ' . count($bookings_data['data']) . ' existing bookings. Please handle them first.');
}
}
// Proceed with deletion
$result = delete_customer($customer_id);
echo 'Customer deleted successfully. ID: ' . $result['deleted_customer_id'];
return $result;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
return false;
}
}
// Usage
safe_delete_customer(123);
?>
Bulk Deletion Example
// Bulk delete customers (use with caution)
async function bulkDeleteCustomers(customerIds) {
const results = [];
const errors = [];
for (const customerId of customerIds) {
try {
const result = await deleteCustomer(customerId);
results.push({ id: customerId, success: true, data: result });
} catch (error) {
errors.push({ id: customerId, success: false, error: error.message });
}
// Add delay to avoid overwhelming the server
await new Promise(resolve => setTimeout(resolve, 100));
}
return { results, errors };
}
// Usage
const customerIdsToDelete = [123, 124, 125];
const bulkResult = await bulkDeleteCustomers(customerIdsToDelete);
console.log('Successful deletions:', bulkResult.results.length);
console.log('Failed deletions:', bulkResult.errors.length);
if (bulkResult.errors.length > 0) {
console.log('Errors:', bulkResult.errors);
}
Best Practices
Before Deleting
- Check for Bookings: Always verify that the customer has no existing bookings before deletion
- Backup Data: Consider exporting customer data before deletion for record-keeping
- User Confirmation: Always require explicit user confirmation for deletion operations
- Audit Trail: Log deletion operations for audit purposes
Alternative to Deletion
Instead of deleting customers, consider:- Deactivating: Set customer status to
inactiveinstead of deleting - Archiving: Move customer data to an archive table
- Soft Delete: Mark as deleted without removing from database
// Alternative: Deactivate instead of delete
async function deactivateCustomer(customerId) {
return await fetch(`https://your-site.com/wp-json/latepoint-api/v1/customers/${customerId}`, {
method: 'PUT',
headers: {
'X-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
status: 'inactive'
})
});
}
