Skip to main content
Collection builds one contact per sending address, so one person or organization can end up as several: a gym writing from its own address and from the booking platform it uses, say. merge_contacts folds those duplicates into the contact you keep, in one write. Find the ids with search_contacts. To move a single address between two contacts that are different people, use update_contact; to drop a contact without keeping anything from it, delete_contact.
The merged contacts are deleted, from the account and from every device connected over CardDAV. This tool is annotated destructive; clients that gate on destructiveHint will ask before calling it. The result carries everything needed to undo it by hand.

Parameters

string
required
The contact to keep, as printed by search_contacts under contact_id. Its name, organization and birthday win.
string[]
required
The contacts to fold into it and then delete. One to ten ids.
string
The address mail to this contact should go to, from any of the contacts. Omit it to keep the preferred address the kept contact has now.

What the merge does

The update of the kept contact and the deletion of the others go out as one change, so a phone syncing the address book never shows a half-merged state. After the merge, mail from any of the merged addresses updates the kept contact; collection never creates a new contact for them. Within a moment of the merge, before the server’s search index has caught up, a message from a merged address can still create a fresh collected contact; the next message from that address folds it back into the kept contact.

Example

Call
Result

Undoing a merge

There is no unmerge. The result lists each deleted contact with its addresses, phone numbers, postal addresses, birthday and note, and names the addresses that moved onto the kept contact. To reverse a merge, remove those moved addresses from the kept contact with update_contact (removedEmails), then recreate each removed contact with create_contact. The interaction history stays on the kept contact.

Errors

Each of these changes nothing:
  • <id> is the contact to keep and cannot also be merged into itself. — list only the other contacts in mergeContactIds.
  • No contact with id <id>. — an id does not resolve. Find it with search_contacts.
  • <address> is on none of these contacts. Their addresses: … — preferredEmail names an address none of the contacts hold; the error lists the ones they do.
  • Could not update the contact to keep: its address book is read-only. — the kept contact sits in an address book the account cannot write.
If the server deletes a merged contact but refuses the update of the kept one, the result says so and lists the deleted contacts’ details for create_contact. If it updates the kept contact but refuses to delete a merged one, the result names it. Running merge_contacts again with only the ids it names finishes the merge without counting their history twice.