> ## Documentation Index
> Fetch the complete documentation index at: https://docs-restapi.wplimit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Customer

> Update an existing customer in the system

## Description

This endpoint allows you to update an existing customer's information in the LatePoint system. You can modify any customer field including personal details, contact information, status, and custom fields.

## Authentication

<ParamField header="X-API-Key" type="string" required>
  Your LatePoint API Key with write permissions
</ParamField>

## Path Parameters

<ParamField path="id" type="integer" required>
  Unique ID of the customer to update
</ParamField>

## Request Body

### Basic Information

<ParamField body="first_name" type="string">
  Customer's first name
</ParamField>

<ParamField body="last_name" type="string">
  Customer's last name
</ParamField>

<ParamField body="email" type="string">
  Customer's email address (must be unique)
</ParamField>

<ParamField body="phone" type="string">
  Customer's phone number
</ParamField>

### Status and Settings

<ParamField body="status" type="string">
  Customer status

  **Possible values:**

  * `active` - Active customer
  * `inactive` - Inactive customer
  * `pending_verification` - Pending email verification
  * `blocked` - Blocked customer
</ParamField>

<ParamField body="is_guest" type="boolean">
  Whether the customer is a guest (no account)
</ParamField>

### Address Information

<ParamField body="address" type="string">
  Street address
</ParamField>

<ParamField body="city" type="string">
  City name
</ParamField>

<ParamField body="state" type="string">
  State or province
</ParamField>

<ParamField body="zipcode" type="string">
  ZIP or postal code
</ParamField>

<ParamField body="country" type="string">
  Country code (ISO 3166-1 alpha-2)
</ParamField>

### Additional Information

<ParamField body="notes" type="string">
  Internal notes about the customer
</ParamField>

<ParamField body="avatar_image_id" type="integer">
  WordPress media ID for customer avatar
</ParamField>

<ParamField body="custom_fields" type="object">
  Custom fields as key-value pairs
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the update was successful
</ResponseField>

<ResponseField name="message" type="string">
  Success message
</ResponseField>

<ResponseField name="data" type="object">
  Updated customer information

  <Expandable title="Updated Customer">
    <ResponseField name="id" type="integer">
      Unique ID of the updated customer
    </ResponseField>

    <ResponseField name="first_name" type="string">
      Customer's first name
    </ResponseField>

    <ResponseField name="last_name" type="string">
      Customer's last name
    </ResponseField>

    <ResponseField name="email" type="string">
      Customer's email address
    </ResponseField>

    <ResponseField name="phone" type="string">
      Customer's phone number
    </ResponseField>

    <ResponseField name="status" type="string">
      Customer status
    </ResponseField>

    <ResponseField name="updated_at" type="string">
      Timestamp of last update
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

### Update Basic Information

```bash theme={null}
curl -X PUT "https://your-site.com/wp-json/latepoint-api/v1/customers/123" \
  -H "X-API-Key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "John",
    "last_name": "Smith",
    "phone": "+1-555-0199"
  }'
```

### Update Status and Email

```bash theme={null}
curl -X PUT "https://your-site.com/wp-json/latepoint-api/v1/customers/123" \
  -H "X-API-Key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john.smith.new@example.com",
    "status": "active"
  }'
```

### Update Address Information

```bash theme={null}
curl -X PUT "https://your-site.com/wp-json/latepoint-api/v1/customers/123" \
  -H "X-API-Key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "address": "456 Oak Street",
    "city": "Los Angeles",
    "state": "CA",
    "zipcode": "90210",
    "country": "US"
  }'
```

## Response Examples

### Successful Update

```json theme={null}
{
  "success": true,
  "message": "Customer updated successfully",
  "data": {
    "id": 123,
    "first_name": "John",
    "last_name": "Smith",
    "email": "john.smith.new@example.com",
    "phone": "+1-555-0199",
    "status": "active",
    "updated_at": "2024-01-15 14:30:25"
  }
}
```

### Validation Error

```json theme={null}
{
  "code": "customer_update_failed",
  "message": "Error updating customer: Email already exists",
  "data": {
    "status": 400
  }
}
```

### Customer Not Found

```json theme={null}
{
  "code": "customer_not_found",
  "message": "Customer not found",
  "data": {
    "status": 404
  }
}
```

## Error Codes

| Code                      | Status | Description                              |
| ------------------------- | ------ | ---------------------------------------- |
| `customer_not_found`      | 404    | Customer with specified ID doesn't exist |
| `customer_update_failed`  | 400    | Validation error or update failed        |
| `latepoint_not_available` | 503    | LatePoint plugin not loaded              |
| `server_error`            | 500    | Internal server error                    |

## JavaScript Example

```javascript theme={null}
// Update customer information
async function updateCustomer(customerId, updateData) {
  try {
    const response = 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(updateData)
    });
    
    const result = await response.json();
    
    if (result.success) {
      console.log('Customer updated:', result.data);
      return result.data;
    } else {
      throw new Error(result.message);
    }
  } catch (error) {
    console.error('Error updating customer:', error);
    throw error;
  }
}

// Usage examples

// Update basic info
const basicUpdate = {
  first_name: 'Jane',
  last_name: 'Doe',
  phone: '+1-555-0123'
};

const updatedCustomer = await updateCustomer(123, basicUpdate);

// Update status
const statusUpdate = {
  status: 'active'
};

await updateCustomer(123, statusUpdate);

// Update with custom fields
const customFieldsUpdate = {
  notes: 'VIP customer',
  custom_fields: {
    preferred_time: 'morning',
    special_requests: 'Quiet room'
  }
};

await updateCustomer(123, customFieldsUpdate);
```

## PHP Example

```php theme={null}
<?php
// Update customer using WordPress HTTP API
function update_customer($customer_id, $update_data) {
    $url = 'https://your-site.com/wp-json/latepoint-api/v1/customers/' . $customer_id;
    
    $response = wp_remote_request($url, array(
        'method' => 'PUT',
        'headers' => array(
            'X-API-Key' => 'your_api_key_here',
            'Content-Type' => 'application/json'
        ),
        'body' => json_encode($update_data)
    ));
    
    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('Update failed: ' . $data['message']);
    }
    
    return $data['data'];
}

// Usage
try {
    $updated_customer = update_customer(123, array(
        'first_name' => 'Updated Name',
        'status' => 'active'
    ));
    
    echo 'Customer updated: ' . $updated_customer['first_name'];
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>
```

## Important Notes

**Email Uniqueness**: The email address must be unique across all customers. If you try to update a customer with an email that already exists, you will receive a validation error.

**Partial Updates**: You only need to include the fields you want to update. Fields not included in the request will remain unchanged.

**Status Changes**: Changing a customer's status may affect their ability to book appointments or access the customer portal.

**Custom Fields**: Custom fields are merged with existing ones. To remove a custom field, set its value to `null` or an empty string.

**WordPress User**: If the customer has an associated WordPress user account, some changes (like email) may also update the WordPress user.
