fastify-xemail
contacts-delete
Delete a SendGrid Marketing contact by ID.
deleteContact
Delete a contact from SendGrid Marketing by contact ID. Returns true if the deletion was accepted (status 200 or 202).
Note: Use searchContact to look up a contact's ID by email before deleting.
Signature
fastify.xEmail.deleteContact(contactId: string): Promise<boolean>
Params
| Name | Type | Required | Description |
|---|---|---|---|
contactId | string | Yes | SendGrid contact ID (obtained from searchContact). |
Returns
Promise<boolean> — true if SendGrid returned status 200 or 202.
Throws
[xEmail] 'contactId' (string) is required for deleteContact().[xEmail] Failed to delete contact: <reason>— SendGrid API error.
Examples
Basic — delete by known ID
fastify.delete("/admin/contacts/:id", async (request) => {
const deleted = await fastify.xEmail.deleteContact(request.params.id);
return { deleted };
});
Realistic — search then delete on unsubscribe
fastify.post("/newsletter/unsubscribe", async (request, reply) => {
const { email } = request.body;
const result = await fastify.xEmail.searchContact(email);
if (!result.found) {
return reply.code(404).send({ error: "Contact not found" });
}
const deleted = await fastify.xEmail.deleteContact(result.contact.id);
if (deleted) {
await db.users.updateMarketingConsent(email, false);
}
return { unsubscribed: deleted };
});
See Also
- contacts-search — Find a contact ID by email before deleting
- contacts-add — Re-add a contact after deletion
AI Context
package: "@xenterprises/fastify-xemail"
method: fastify.xEmail.contactsDelete(contactId)
use-when: Delete a marketing contact by their SendGrid contact ID
params: contactId (string)
returns: Promise<void>
