Skip to the documentation
PHP

Contacts

`contacts->list`, `get`, `create`, `save`, `update`, `setAudiences`, `delete`, `deleteMany`, `listPeople`, `setPhoto`, `removePhoto`, `block`, `unblock`, `listThreads` and `activity`.

Every method

usage.php
$page = $client->contacts->list(limit: 100);$contact = $client->contacts->get('[email protected]'); $saved = $client->contacts->create([    'email' => '[email protected]',    'name' => 'Grace Hopper',    'notes' => 'Met at the compiler workshop',]); $client->contacts->update('[email protected]', ['notes' => null]);$client->contacts->setAudiences('[email protected]', ['audienceIds' => ['aud_4c1b8e2a7d9f05c36b4e8a71']]);$client->contacts->delete('[email protected]'); echo count($page), ' ', $page->hasMore ? 'more to come' : 'that is all', PHP_EOL;echo $contact['source'], ' ', $contact['lastSeenAt'] ?? 'never mailed', ' ', $saved['source'], PHP_EOL;

list returns the most recently seen contacts first, and contacts that have never been mailed last. source is auto when the row was written because a member sent that address a message from the app composer, which is a materially different claim from somebody having saved it. Mail arriving from an address writes nothing, and neither does a send through this API.

The book belongs to the workspace rather than to one person, so a contact saved by any member is the contact every member and every key sees. create writes source as manual and puts the contact in the default audience as it is written. Name lists of your own in audienceIds to join them in the same call, which also needs audiences:write, or add the contact later with audiences->addContact, which the Audiences page covers. setAudiences says exactly which lists a contact is in, in one call.

Addresses are stored lowercased and the client encodes the one you pass, so [email protected] reaches the right row. An empty address throws InvalidArgumentException before anything is sent. The address is the identity, so update cannot change it: moving a contact is a delete and a create.

Parameters: contacts->list

limitint
How many contacts to return per page: a whole number from 1 to 200, defaulting to 50. A value outside the range is a 422 rather than a clamped one. The argument is typed `int`, so cast a value read off a query string with `(int)` first.
cursorstring
The `nextCursor` from the previous page. Never build one yourself: a cursor naming a contact that no longer exists is a 400 `invalid_cursor`, thrown as an `InvalidRequestException`, which means your paging state is stale and the walk should restart without a cursor.
sourcestring
`manual` for the contacts somebody saved on purpose, `auto` for the ones the app composer recorded. Leave it out for the whole book.
qstring
Searches the name and the address, up to 200 characters. When nothing matches exactly on the first page, close spellings are returned instead, and the pages that follow keep matching the same way.

Response: a contact

contacts->list returns an OpenEmail\Result\Page, so the rows are on $page->items and the walk follows $page->nextCursor while $page->hasMore is true. listAll returns every row as one array, and iterate returns a Generator that yields them one at a time. get, create, update, save and setAudiences each return one contact as an array keyed in camelCase, the same row plus audiences. The address book is unbounded, which is why this route pages rather than returning an array that silently stopped at 200.

objectstring
Always the string `contact`, on the list rows as well as on `get`.
emailstring
The address, lowercased on write so `[email protected]` and `[email protected]` are one contact, and the key every contacts method takes, since no contact id is exposed. Rows belong to the workspace rather than to the member or the key that wrote them, so every member and every key on the workspace reads and writes one address book.
namestring or null
The display name, or null when no name has ever been recorded for the address. An automatic write carries one only when the header supplied something other than the address itself, and it can never overwrite a name the user typed.
sourcestring
`auto` means the row was written because the user sent mail to that address. `manual` means somebody entered it by hand, a materially different claim, and an upsert never downgrades `manual` back to `auto`. Mail arriving from an address writes no row at all, deliberately, so somebody who has only ever written to you is not in here. Treat the value as an open string, because the column is free text defaulting to `manual`.
notesstring or null
Free text somebody wrote about this person, in the app or through `update`, never generated. It is null when nobody has written any, and `'notes' => null` on `update` clears it.
lastSeenAtstring or null
An ISO 8601 UTC string, bumped every time a member sends to that address from the app composer, not when mail arrives from it, which writes nothing. It is null on a contact saved through `create` that has never been mailed, and those sort last in the descending `lastSeenAt` order this route returns.
audiencesarray
Only on `get`, `create`, `update`, `save` and `setAudiences`, never on list rows. Every audience the contact is in, the default one included, as an array with `id`, `name` and `builtin`. `builtin` is `default` on the audience every contact belongs to and null on one somebody created, so branch on it rather than on the name, which anybody can change.
photoUrlstring or null
Where the contact photo is served, or null when the contact has none. `setPhoto` sets it and every upload gets a new URL.

Setting a contact’s audiences

setAudiences($email, ['audienceIds' => [...]]) says exactly which audiences one contact is in, in one request. The contact joins every audience listed that it is not in yet and leaves every other one, and the call returns the contact after the change, with its audiences. It needs audiences:write, because it writes memberships rather than the contact, and repeating it changes nothing, so the client retries it after a network failure.

The default audience is always kept, so 'audienceIds' => [] leaves the contact in the default audience alone. It takes up to 100 ids. An id that names no audience in this workspace is a 404 audience_not_found and nothing changes, and an address that is not a contact is a 404 contact_not_found. Both throw a NotFoundException.

Everyone on the Contacts page

listPeople lists the people the Contacts page in the app shows: the saved contacts and every address seen in mail, each with saved, threads and lastAt. list is the saved contacts alone. It returns an OpenEmail\Result\PeoplePage, which adds seen to items, hasMore and nextCursor. The addresses seen in mail come only when the key also holds threads:read, and $page->seen says whether they did. sort: is recent, name or threads, and OpenEmail\Constants\PeopleSorts names them. q: searches names, addresses and notes, and blocked: true keeps the people the workspace blocklist blocks, whole-domain rules included. blockedBy names the rule on every row.

people.php
use OpenEmail\Constants\PeopleSorts; $page = $client->contacts->listPeople(sort: PeopleSorts::THREADS, limit: 50); foreach ($page as $person) {    if (!$person['saved'] && $person['threads'] > 5) {        $client->contacts->save($person['email']);    }} $blocked = $client->contacts->listAllPeople(blocked: true);echo $page->seen ? 'saved and seen' : 'saved only', ', ', count($blocked), ' blocked', PHP_EOL;

listAllPeople returns every page as one array, and iteratePeople returns a Generator that yields each person. Neither reports seen, so read one page with listPeople to learn it. The cursor is opaque, so pass nextCursor back as cursor: exactly as it came, with the same sort:, q: and blocked:.

Saving, deleting and photos

save($email), with an optional array of name and notes, is Add to contacts and Keep in contacts: it saves an address that is not a contact yet, keeps one recorded from a send as saved by hand, and brings back a deleted one. delete is Delete: it removes the saved contact and hides the address, so the composer does not record it again, and it takes an address only ever seen in mail too. wasSaved in the array it returns says which it was. deleteMany deletes up to 200 in one call.

photo.php
$client->contacts->save('[email protected]', ['name' => 'Grace Hopper']); $contact = $client->contacts->setPhoto('[email protected]', file_get_contents('photo.jpg'), contentType: 'image/jpeg');echo $contact['photoUrl'], PHP_EOL; $client->contacts->setPhoto('[email protected]', new \SplFileInfo('avatar.png')); $client->contacts->removePhoto('[email protected]');$client->contacts->deleteMany(['[email protected]', '[email protected]']);

setPhoto sends the image bytes as they are: PNG, JPEG, WebP or GIF up to 5 MB, fitted into a 512 pixel square. The bytes are a string, a stream resource from fopen, an SplFileInfo, or a PSR-7 stream or uploaded file. Pass contentType:, or bytes that carry their own type: a PSR-7 uploaded file, or a Symfony or Laravel upload, with its media type, or a file or stream whose name ends in .png, .jpg, .jpeg, .webp or .gif. Without a type the bytes go as application/octet-stream, which the server refuses with a 422 invalid_image. OpenEmail\Constants\ContactPhotoTypes names the four types. The address has to be a saved contact first.

Blocking

block($email) puts the address on the workspace blocklist so mail from it is refused, dropping any plus tag, and unblock($email) takes off every rule that blocks it. Both need settings:write, because they change the blocklist rather than the contact, and neither needs the address to be a contact.

When unblock lifts a whole-domain rule, removed lists it with list set to blockedDomains, and everybody at that domain is unblocked with it. OpenEmail\Constants\ContactBlockLists names both lists.

Conversations and activity

listThreads($email) pages through the threads the address wrote or was written to, in every folder, and listAllThreads and iterateThreads walk them. activity($email) returns the numbers behind a contact’s Activity tab: received and sent per bucket, threads waiting on your reply, and the median reply time each way. Both need threads:read.

activity.php
$threads = $client->contacts->listThreads('[email protected]', q: 'invoice'); $activity = $client->contacts->activity(    '[email protected]',    minutes: 30 * 24 * 60,    grain: 'day',    offsetMinutes: intdiv((int) date('Z'), 60),); echo count($threads), ' threads, ', $activity['totals']['waiting'], ' waiting on you', PHP_EOL;

activity takes named arguments. minutes: sets the window, which is 90 days when left out. grain: sets the bucket width: minute, hour or day. offsetMinutes: sets the minutes east of UTC where days break, and intdiv((int) date('Z'), 60) is the offset of the zone PHP is set to.