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

# Update Contact

> Update an existing contact with new information

This endpoint allows you to update the information of an existing contact in your organization's database. You only need to include the fields you want to modify - any fields not included in the request will remain unchanged.

## Use Cases

* Update a contact's phone number, email, or other contact information
* Add or modify additional data fields for a contact
* Enrich contact records with new information from external sources
* Update contact status or notes after interaction

## Path Parameters

<ParamField path="contactId" type="string" required>
  The unique identifier of the contact you want to update. This is a UUID string that was generated when the contact was created.
</ParamField>

## Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication. You can find this in your dashboard under API settings.
</ParamField>

## Body Parameters

<ParamField body="phone_number" type="string">
  The updated phone number of the contact in international format (e.g., +12124567890)
</ParamField>

<ParamField body="full_name" type="string">
  The updated full name of the contact
</ParamField>

<ParamField body="country" type="string">
  The updated country of the contact
</ParamField>

<ParamField body="email" type="string">
  The updated email address of the contact
</ParamField>

<ParamField body="description" type="string">
  Updated description or notes about the contact
</ParamField>

<ParamField body="additional_data" type="array">
  Updated array of additional data fields for the contact. Note that this will replace the entire additional\_data array, not merge with existing values.

  <Expandable title="additional_data object">
    <ParamField body="type" type="string" required>
      The type of the data field (e.g., "text", "date", "number", "location")
    </ParamField>

    <ParamField body="field" type="string" required>
      The name of the data field
    </ParamField>

    <ParamField body="value" type="string" required>
      The value of the data field
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="status code" type="number">
  200 on successful update
</ResponseField>

<ResponseField name="id" type="string">
  The unique identifier of the updated contact (UUID format)
</ResponseField>

<ResponseField name="created_at" type="string">
  The timestamp when the contact was originally created (ISO 8601 format)
</ResponseField>

<ResponseField name="phone_number" type="string">
  The updated phone number of the contact
</ResponseField>

<ResponseField name="full_name" type="string">
  The updated full name of the contact
</ResponseField>

<ResponseField name="country" type="string">
  The updated country of the contact
</ResponseField>

<ResponseField name="email" type="string">
  The updated email of the contact
</ResponseField>

<ResponseField name="description" type="string">
  Updated description or notes about the contact
</ResponseField>

<ResponseField name="additional_data" type="array">
  Updated additional data associated with the contact
</ResponseField>

<ResponseField name="organization_id" type="string">
  The ID of the organization the contact belongs to
</ResponseField>

## Error Codes

* `400 Bad Request` - Invalid input data format
* `401 Unauthorized` - Invalid or missing API key
* `404 Not Found` - Contact not found
* `409 Conflict` - The update would create a duplicate phone number
* `500 Internal Server Error` - Server-side error

## Code Examples

<RequestExample>
  ```bash cURL Example (Update name and description) theme={null}
  # Update a contact's name and description
  curl -X PATCH "https://api.contactship.ai/v1/contacts/c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6" \
    -H "x-api-key: your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "full_name": "Juan Carlos Pérez",
      "description": "Lead converted to customer"
    }'
  ```

  ```bash cURL Example (Update multiple fields) theme={null}
  # Update multiple contact fields
  curl -X PATCH "https://api.contactship.ai/v1/contacts/c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6" \
    -H "x-api-key: your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "phone_number": "+12125678901",
      "email": "juan.perez@ejemplo.com",
      "additional_data": [
        {
          "type": "location",
          "field": "dirección",
          "value": "Av. Reforma 456"
        },
        {
          "type": "text",
          "field": "notas",
          "value": "Cliente activo con suscripción premium"
        },
        {
          "type": "date",
          "field": "fecha_conversión",
          "value": "2023-03-15"
        }
      ]
    }'
  ```

  ```javascript JavaScript Example theme={null}
  // Using Fetch API to update a contact
  const updateContact = async (contactId, updateData) => {
    try {
      const response = await fetch(`https://api.contactship.ai/v1/contacts/${contactId}`, {
        method: 'PATCH',
        headers: {
          'x-api-key': 'your-api-key',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(updateData)
      });
      
      if (!response.ok) {
        if (response.status === 404) {
          console.error('Contact not found');
          return null;
        }
        const errorData = await response.json();
        throw new Error(`HTTP error! Status: ${response.status}, Message: ${errorData.message || 'Unknown error'}`);
      }
      
      const updatedContact = await response.json();
      console.log('Contact updated:', updatedContact);
      return updatedContact;
    } catch (error) {
      console.error('Error updating contact:', error);
    }
  };

  // Example usage
  const contactId = 'c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6';
  const updateData = {
    full_name: 'Juan Carlos Pérez',
    email: 'juan.perez@ejemplo.com',
    description: 'Lead converted to customer'
  };

  updateContact(contactId, updateData);
  ```

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

  # Replace with your actual API key
  api_key = "your-api-key"

  # Base URL for the API
  base_url = "https://api.contactship.ai"

  # Contact ID to update
  contact_id = "c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6"

  # Headers
  headers = {
      "x-api-key": api_key,
      "Content-Type": "application/json"
  }

  # Update data - only include fields you want to change
  update_data = {
      "email": "juan.perez@ejemplo.com",
      "description": "Lead converted to customer",
      "additional_data": [
          {
              "type": "location",
              "field": "dirección",
              "value": "Av. Reforma 456"
          },
          {
              "type": "date",
              "field": "fecha_conversión",
              "value": "2023-03-15"
          }
      ]
  }

  # Make the PATCH request
  response = requests.patch(
      f"{base_url}/v1/contacts/{contact_id}", 
      headers=headers,
      data=json.dumps(update_data)
  )

  # Check if the request was successful
  if response.status_code == 200:
      updated_contact = response.json()
      print(f"Contact updated successfully: {updated_contact['full_name']}")
      
      # Print updated field information
      if 'email' in update_data:
          print(f"New email: {updated_contact['email']}")
      
      if 'additional_data' in update_data:
          print("Updated additional information:")
          for data in updated_contact['additional_data']:
              print(f"  {data['field']}: {data['value']} ({data['type']})")
              
  elif response.status_code == 404:
      print("Error: Contact not found")
  else:
      print(f"Error: {response.status_code}")
      print(response.text)
  ```
</RequestExample>

<ResponseExample>
  ```json Example Response theme={null}
  {
    "id": "c1a2b3c4-d5e6-f7g8-h9i0-j1k2l3m4n5o6",
    "created_at": "2023-01-01T12:00:00Z",
    "phone_number": "+12125678901",
    "full_name": "Juan Carlos Pérez",
    "country": "México",
    "email": "juan.perez@ejemplo.com",
    "description": "Lead converted to customer",
    "additional_data": [
      {
        "type": "location",
        "field": "dirección",
        "value": "Av. Reforma 456"
      },
      {
        "type": "text",
        "field": "notas",
        "value": "Cliente activo con suscripción premium"
      },
      {
        "type": "date",
        "field": "fecha_conversión",
        "value": "2023-03-15"
      }
    ],
    "organization_id": "org123456"
  }
  ```
</ResponseExample>

## Notes and Best Practices

* Only include the fields you want to update in the request body
* Be careful when updating the additional\_data array, as it will replace the entire array rather than merge with existing values
* If you're updating a phone number, ensure it doesn't conflict with another contact's phone number
* Consider implementing validation checks before submitting updates
* Keep track of contact update history in your application if needed for compliance or audit purposes
