Contacts

get()

api.mail.contacts.get(address) → Promise<Contact|null>

One contact by address — or null when there is none. It does not throw.

freenull, not 404by address
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const contact = await api.mail.contacts.get("fedy@example.net");

if (contact) showName(contact.name);
else showAddress("fedy@example.net");
contact = api.mail.contacts.get("fedy@example.net")

if contact:
    show_name(contact["name"])
else:
    show_address("fedy@example.net")

null is the normal answer

Most correspondents are not in an address book

Throwing for the common case would mean wrapping every lookup in a try. null is what « this person is not saved » looks like.

The address is the key, exactly

A correspondent writing from a second address is a second contact. Nothing is merged, and nothing guesses that two addresses are the same person.

For a list, fetch once

// Not one get() per row
const byAddress = new Map((await api.mail.contacts.list()).map((c) => [c.address, c]));
# Not one get() per row
by_address = {c["address"]: c for c in api.mail.contacts.list()}

Messages already carry the picture

from.avatar on a message is already resolved through the whole chain. This call is for an address book page, not for displaying a message.