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

# Update Customer

> Update existing customer profiles and information through Caibo IPG API

# Overview

Update existing customer profiles in the Caibo IPG system to maintain accurate customer information and payment preferences. This endpoint is essential for maintaining accurate customer data and ensuring optimal payment processing experiences.

<Note>
  Customer updates should be performed whenever customer information changes, such as address updates, contact information changes, or preference modifications.
</Note>

## API Endpoint

* **Method**: `PUT`
* **Path**: `/customers/{id}`
* **id** (required): The unique identifier of the customer to update
  * Type: `integer (int64)`
  * Example: `12345`

## Path Parameters

* **id** (required): The unique identifier of the customer to update
  * Type: `integer (int64)`
  * Example: `12345`

## Request Body

The request body should contain a `Client` object with the updated customer information. You only need to include the fields you want to update.

### Updatable Fields

* **Personal Information**
  * Name
  * Email address
  * Phone number
  * Date of birth

* **Address Information**
  * Billing address
  * Shipping address
  * Country and region

* **Account Preferences**
  * Default currency
  * Language preference
  * Notification settings
  * Communication preferences

* **Account Status**
  * Active/inactive status
  * Account verification status
  * Subscription preferences

## Integration Examples

### Basic Customer Update

```javascript theme={null}
// Update customer information
const customerId = 12345;
const updateData = {
  email: "newemail@example.com",
  phone: "+1234567890",
  address: {
    street: "456 New Street",
    city: "San Francisco",
    state: "CA",
    zipCode: "94105",
    country: "US"
  }
};

const response = await fetch(`/api/customers/${customerId}`, {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer ' + accessToken,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(updateData)
});

if (response.ok) {
  console.log('Customer updated successfully');
} else {
  console.error('Update failed:', response.statusText);
}
```

### Partial Customer Update

```javascript theme={null}
// Update only specific fields
const customerId = 12345;
const partialUpdate = {
  preferences: {
    currency: "EUR",
    notifications: false,
    language: "fr"
  }
};

const response = await fetch(`/api/customers/${customerId}`, {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer ' + accessToken,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(partialUpdate)
});
```

### Update with Validation

```javascript theme={null}
// Update customer with validation
async function updateCustomer(customerId, updateData) {
  try {
    // Validate update data
    if (updateData.email && !isValidEmail(updateData.email)) {
      throw new Error('Invalid email format');
    }
    
    if (updateData.phone && !isValidPhone(updateData.phone)) {
      throw new Error('Invalid phone format');
    }
    
    const response = await fetch(`/api/customers/${customerId}`, {
      method: 'PUT',
      headers: {
        'Authorization': 'Bearer ' + accessToken,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(updateData)
    });
    
    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`Update failed: ${errorData.message}`);
    }
    
    return await response.json();
  } catch (error) {
    console.error('Customer update error:', error);
    throw error;
  }
}
```

## Response Codes

### Success Response

* **200 OK**: Customer updated successfully

### Error Responses

* **400 Bad Request**: Invalid request data or validation errors
* **401 Unauthorized**: Invalid or missing authentication credentials
* **404 Not Found**: Customer with specified ID does not exist

## Error Handling

### Common Error Scenarios

1. **Customer Not Found**
   * Status: `404 Not Found`
   * Cause: Invalid customer ID or customer has been deleted
   * Solution: Verify the customer ID exists before attempting update

2. **Validation Errors**
   * Status: `400 Bad Request`
   * Cause: Invalid data format, missing required fields, or constraint violations
   * Solution: Validate data before sending the request

3. **Authentication Errors**
   * Status: `401 Unauthorized`
   * Cause: Invalid, expired, or missing authentication token
   * Solution: Refresh authentication token and retry

### Error Response Format

```json theme={null}
{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "Bad Request",
  "status": 400,
  "detail": "Invalid email format",
  "instance": "/customers/12345"
}
```

## Best Practices

### Data Validation

1. **Client-Side Validation**: Validate data before sending to reduce server errors
2. **Format Checking**: Ensure email, phone, and address formats are correct
3. **Required Fields**: Check that all required fields are provided
4. **Data Sanitization**: Clean and sanitize user input before processing

### Update Strategy

1. **Partial Updates**: Only send fields that have changed to minimize data transfer
2. **Optimistic Updates**: Update UI immediately, then sync with server
3. **Conflict Resolution**: Handle cases where data has been modified by another process
4. **Audit Trail**: Log all customer updates for compliance and debugging

### Security Considerations

1. **Authorization**: Ensure users can only update their own profiles or have proper permissions
2. **Data Validation**: Validate all input data to prevent injection attacks
3. **Rate Limiting**: Implement rate limiting to prevent abuse
4. **Sensitive Data**: Handle sensitive information with extra care

## Use Cases

### Profile Management

* **Contact Updates**: When customers change email or phone numbers
* **Address Changes**: When customers move or update billing/shipping addresses
* **Preference Updates**: When customers modify notification or payment preferences

### Account Management

* **Status Changes**: Activating, deactivating, or suspending customer accounts
* **Verification Updates**: Updating verification status after identity checks
* **Subscription Changes**: Modifying subscription levels or preferences

### Compliance Updates

* **GDPR Compliance**: Updating consent preferences and data processing agreements
* **KYC Updates**: Refreshing Know Your Customer information as required
* **Tax Information**: Updating tax-related customer information

## Integration Considerations

### Before Updating

1. **Fetch Current Data**: Get current customer information to avoid overwriting unchanged fields
2. **User Permissions**: Verify the requesting user has permission to update the customer
3. **Data Backup**: Consider backing up current data before major updates

### After Updating

1. **Confirmation**: Send confirmation to customer about profile changes
2. **Audit Logging**: Log the update for compliance and troubleshooting
3. **Cache Invalidation**: Clear any cached customer data to ensure consistency
4. **Downstream Systems**: Notify other systems that depend on customer data

## Next Steps

<Card title="Create Customer" icon="user-plus" href="/ipg/create_customer">
  Learn how to create new customer profiles
</Card>

<Card title="User Payment Methods" icon="credit-card" href="/ipg/user-payment-methods">
  Manage customer's saved payment methods
</Card>

<Card title="Customer Authentication" icon="key" href="/ipg/authentication">
  Implement secure customer authentication
</Card>


## OpenAPI

````yaml api PUT /customers/{id}
openapi: 3.0.4
info:
  title: FinHub API
  description: >-
    FinHub API provides services for the Caibo platform to support client's
    applications
  version: v1
servers:
  - url: https://apay.caibo.digital
    description: Caibo APay server (Test and Production share base; method IDs differ)
security: []
paths:
  /customers/{id}:
    put:
      tags:
        - Customers
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
            format: int64
      requestBody:
        content:
          application/json-patch+json:
            schema:
              $ref: '#/components/schemas/Client'
          application/json:
            schema:
              $ref: '#/components/schemas/Client'
          text/json:
            schema:
              $ref: '#/components/schemas/Client'
          application/*+json:
            schema:
              $ref: '#/components/schemas/Client'
      responses:
        '200':
          description: OK
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
components:
  schemas:
    Client:
      required:
        - email
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
        ownerId:
          type: integer
          format: int64
        userId:
          type: integer
          format: int64
          nullable: true
        ownerName:
          type: string
          nullable: true
        name:
          maxLength: 100
          minLength: 0
          type: string
        email:
          maxLength: 100
          minLength: 0
          type: string
          format: email
        address:
          maxLength: 255
          minLength: 0
          type: string
          nullable: true
        phone:
          maxLength: 20
          minLength: 0
          type: string
          nullable: true
        memberId:
          maxLength: 50
          minLength: 0
          type: string
          nullable: true
        hasPaymentRequests:
          type: boolean
          nullable: true
        totalDeposits:
          type: number
          format: double
          nullable: true
        createDate:
          type: string
          format: date-time
      additionalProperties: false
    ProblemDetails:
      type: object
      properties:
        type:
          type: string
          nullable: true
        title:
          type: string
          nullable: true
        status:
          type: integer
          format: int32
          nullable: true
        detail:
          type: string
          nullable: true
        instance:
          type: string
          nullable: true
      additionalProperties: {}

````