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

# Contacts

> Create, list, retrieve and update contacts via the Zavu PHP SDK. Manage profile metadata, channels and merge suggestions from your code.

Contacts are automatically created when you send messages. You can retrieve and update contact information.

## Get Contact

```php theme={null}
$result = $client->contacts->get([
    'contactId' => 'con_abc123',
]);

echo $result->id . "\n";
echo $result->phoneNumber . "\n";
echo $result->countryCode . "\n";
echo implode(', ', $result->availableChannels) . "\n";
echo $result->defaultChannel . "\n";
```

## Get Contact by Phone

```php theme={null}
$result = $client->contacts->getByPhone([
    'phoneNumber' => '+14155551234',
]);

echo $result->id . "\n";
echo implode(', ', $result->availableChannels) . "\n"; // ["sms", "whatsapp"]
```

## Create Contact

```php theme={null}
$result = $client->contacts->create([
    'displayName' => 'John Doe',
    'channels' => [
        [
            'channel' => 'sms',
            'identifier' => '+14155551234',
            'isPrimary' => true,
        ],
        [
            'channel' => 'whatsapp',
            'identifier' => '+14155551234',
            'isPrimary' => true,
        ],
        [
            'channel' => 'email',
            'identifier' => 'john@example.com',
            'isPrimary' => true,
        ],
    ],
    'metadata' => [
        'source' => 'import',
    ],
]);

echo $result->id . "\n";
echo $result->displayName . "\n";
```

## Update Contact

```php theme={null}
$result = $client->contacts->update([
    'contactId' => 'con_abc123',
    'defaultChannel' => 'whatsapp',
    'metadata' => [
        'name' => 'John Doe',
        'tier' => 'premium',
    ],
]);
```

## List Contacts

```php theme={null}
$result = $client->contacts->list([
    'limit' => 50,
]);

foreach ($result->items as $contact) {
    echo $contact->id . " " . $contact->phoneNumber . "\n";
}

// Filter by phone number
$result = $client->contacts->list([
    'phoneNumber' => '+1415',
]);

// Pagination
$cursor = null;
do {
    $result = $client->contacts->list(['cursor' => $cursor, 'limit' => 50]);
    foreach ($result->items as $contact) {
        echo $contact->id . "\n";
    }
    $cursor = $result->nextCursor;
} while ($cursor !== null);
```

## Add Channel to Contact

```php theme={null}
$result = $client->contacts->addChannel([
    'contactId' => 'con_abc123',
    'channel' => 'email',
    'identifier' => 'john.work@company.com',
    'label' => 'work',
]);

echo $result->channel->id . "\n";
```

## Update Channel

```php theme={null}
$result = $client->contacts->updateChannel([
    'contactId' => 'con_abc123',
    'channelId' => 'ch_xyz789',
    'label' => 'personal',
    'verified' => true,
]);
```

## Set Channel as Primary

```php theme={null}
$result = $client->contacts->setPrimaryChannel([
    'contactId' => 'con_abc123',
    'channelId' => 'ch_xyz789',
]);
```

## Remove Channel

```php theme={null}
$client->contacts->removeChannel([
    'contactId' => 'con_abc123',
    'channelId' => 'ch_xyz789',
]);
```

<Warning>
  You cannot remove the last channel from a contact.
</Warning>

## Merge Contacts

```php theme={null}
$result = $client->contacts->merge([
    'contactId' => 'con_abc123',
    'sourceContactId' => 'con_xyz789',
]);

echo $result->id . "\n"; // merged contact
```

## Dismiss Merge Suggestion

```php theme={null}
$client->contacts->dismissMergeSuggestion([
    'contactId' => 'con_abc123',
]);
```

## Phone Introspection

Validate a phone number and check available channels:

```php theme={null}
$result = $client->introspect->phone([
    'phoneNumber' => '+14155551234',
]);

echo $result->validNumber . "\n"; // true
echo $result->countryCode . "\n"; // "US"
echo $result->nationalFormat . "\n"; // "(415) 555-1234"
echo $result->lineType . "\n"; // "mobile"
echo implode(', ', $result->availableChannels) . "\n"; // ["sms", "whatsapp"]
echo $result->carrier?->name . "\n"; // "Verizon Wireless"
```
