update_contact
Modify specific details for an existing contact in iCloud Contacts while preserving unchanged information.
Instructions
Update an existing contact in iCloud Contacts. Only provided fields are changed; others are preserved.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | Contact ID to update | |
| firstName | No | ||
| lastName | No | ||
| fullName | No | ||
| org | No | ||
| phone | No | ||
| No | |||
| phones | No | ||
| emails | No | ||
| addresses | No | ||
| birthday | No | ||
| note | No | ||
| url | No |
Implementation Reference
- lib/carddav.js:362-388 (handler)The handler implementation for the `update_contact` tool, which fetches an existing contact, merges new fields, and updates it back to the CardDAV server using a PUT request with ETag validation.
export async function updateContact(contactId, fields) { const { dataHost, addressBookPath } = await discover(); const url = `${dataHost}${addressBookPath}${contactId}.vcf`; // Fetch existing to get etag and merge fields const existing = await davRequest('GET', url); if (existing.status === 404) throw new Error(`Contact not found: ${contactId}`); const current = parseVCard(existing.body); // Merge: new fields override, but keep arrays from existing if not overridden const merged = { ...current, ...fields }; // Preserve the original VCARD UID (which may differ from the filename UUID) const vcard = serializeVCard(merged, current.uid || contactId); const resp = await davRequest('PUT', url, { contentType: 'text/vcard; charset=utf-8', etag: existing.etag, body: vcard, }); if (resp.status !== 204 && resp.status !== 200) { throw new Error(`CardDAV PUT (update) failed: ${resp.status} — ${resp.body.slice(0, 200)}`); } return { updated: true, contactId, etag: resp.etag }; }