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

# Update Customer

> Update an existing customer's information

## Overview

The customer update endpoint allows you to modify existing customer information. You can perform both partial and full updates to customer records.

## Base URL

```bash theme={null}
PATCH /customers/{id}
```

## Authentication

<Note>
  All requests must include your API key in the Authorization header:

  ```bash theme={null}
  Authorization:  YOUR_API_KEY
  ```
</Note>

## Request Parameters

### Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the customer to update
</ParamField>

### Body Parameters

<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. Must be a valid email format.
</ResponseField>

<ResponseField name="phone_number" type="string">
  Customer's phone number in E.164 format (e.g., +2348012345678)
</ResponseField>

<ResponseField name="billing_address" type="object">
  Customer's billing address information

  <Expandable title="billing_address properties">
    <ResponseField name="line1" type="string">
      Primary address line
    </ResponseField>

    <ResponseField name="line2" type="string">
      Secondary address line (optional)
    </ResponseField>

    <ResponseField name="city" type="string">
      City name
    </ResponseField>

    <ResponseField name="state" type="string">
      State or province
    </ResponseField>

    <ResponseField name="zip_code" type="string">
      Postal or ZIP code
    </ResponseField>

    <ResponseField name="country" type="string">
      Two-letter country code (ISO 3166-1 alpha-2)
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH "https://api.spendjuice.com/customers/6f7e1e7f-93d1-4fcc-b7a4-738f869615c8" \
    -H "Authorization:  YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "phone_number": "+2348012345678",
      "billing_address": {
        "line1": "123 Test lane",
        "city": "Anon"
      }
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.spendjuice.com/customers/6f7e1e7f-93d1-4fcc-b7a4-738f869615c8"
  headers = {
      "Authorization": " YOUR_API_KEY",
      "Content-Type": "application/json"
  }
  data = {
      "phone_number": "+2348012345678",
      "billing_address": {
          "line1": "123 Test lane",
          "city": "Anon"
      }
  }

  response = requests.patch(url, headers=headers, json=data)
  print(response.json())
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  const customerUpdate = async () => {
    try {
      const response = await axios.patch(
        'https://api.spendjuice.com/customers/6f7e1e7f-93d1-4fcc-b7a4-738f869615c8',
        {
          phone_number: '+2348012345678',
          billing_address: {
            line1: '123 Test lane',
            city: 'Anon'
          }
        },
        {
          headers: {
            'Authorization': ' YOUR_API_KEY',
            'Content-Type': 'application/json'
          }
        }
      );
      return response.data;
    } catch (error) {
      console.error('Error updating customer:', error.response.data);
    }
  };
  ```
</CodeGroup>

## Response

### Success Response (200 OK)

```json theme={null}
{
    "data": {
        "id": "6f7e1e7f-93d1-4fcc-b7a4-738f869615c8",
        "first_name": "Test",
        "last_name": "Customer",
        "email": "test@custom.er",
        "phone_number": "+2348012345678",
        "billing_address": {
            "line1": "123 Test lane",
            "line2": "3456 Mike Drive",
            "city": "Anon",
            "state": "Acme",
            "zip_code": "12345",
            "country": "US"
        }
    }
}
```

### Error Responses

<AccordionGroup>
  <Accordion title="400 Bad Request">
    ```json theme={null}
    {
      "error": {
        "code": "invalid_request",
        "message": "Invalid parameters provided",
        "details": {
          "phone_number": ["Invalid phone number format"]
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="404 Not Found">
    ```json theme={null}
    {
      "error": {
        "code": "not_found",
        "message": "Customer not found"
      }
    }
    ```
  </Accordion>

  <Accordion title="422 Unprocessable Entity">
    ```json theme={null}
    {
      "error": {
        "code": "validation_error",
        "message": "The request contains invalid parameters",
        "details": {
          "email": ["Invalid email format"]
        }
      }
    }
    ```
  </Accordion>
</AccordionGroup>

## Update Rules

<Card title="Important Update Considerations">
  * Only provide fields that need to be updated
  * Nested objects (like billing\_address) must be updated as a complete object
  * Empty strings ("") will clear the field value
  * Null values are ignored
  * Phone numbers must be in E.164 format
  * Email addresses must be valid format
</Card>

## Rate Limits

<Warning>
  Customer update requests are limited to:

  * 10 requests per minute per API key
  * 1000 requests per day per API key
</Warning>

## Versioning

The current version of this API is v1. We recommend including a version accept header:

```bash theme={null}
Accept: application/json;version=1
```

## Best Practices

1. **Partial Updates**
   * Only send fields that need to be changed
   * Use PATCH for partial updates
   * Validate data before sending

2. **Error Handling**
   * Implement proper error handling
   * Validate response status codes
   * Log failed update attempts

3. **Idempotency**
   * Use idempotency keys for critical updates
   * Retry failed requests with the same idempotency key

4. **Validation**
   * Validate all input fields client-side
   * Handle validation errors appropriately
   * Check response data matches expected format

<Card title="Need Help?">
  For additional support:

  * Check our [API Reference](/api-reference/overview)
  * Contact [Support](mailto:support@juicyway.com)
  * Join our [Developer Community](https://discord.gg/juice)
</Card>
