remove_contacts_from_list
Remove email addresses from a SendGrid contact list while preserving the contacts in your database. Specify list ID and emails to manage your email marketing audience.
Instructions
Remove contacts from a SendGrid list without deleting them
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | ID of the contact list | |
| emails | Yes | Array of email addresses to remove from the list |
Implementation Reference
- src/tools/index.ts:553-555 (handler)Handler for the 'remove_contacts_from_list' tool call. It invokes the service method with list_id and emails, then returns a success message.case 'remove_contacts_from_list': await service.removeContactsFromList(args.list_id, args.emails); return { content: [{ type: 'text', text: `Removed ${args.emails.length} contacts from list ${args.list_id}` }] };
- src/tools/index.ts:353-373 (schema)Schema definition for the 'remove_contacts_from_list' tool, including name, description, and inputSchema with required properties list_id and emails.{ name: 'remove_contacts_from_list', description: 'Remove contacts from a SendGrid list without deleting them', inputSchema: { type: 'object', properties: { list_id: { type: 'string', description: 'ID of the contact list' }, emails: { type: 'array', items: { type: 'string' }, description: 'Array of email addresses to remove from the list' } }, required: ['list_id', 'emails'] } }
- src/services/sendgrid.ts:130-153 (helper)Helper method in SendGridService that implements the core logic: searches for contacts by email within the specified list, retrieves their IDs, and deletes the associations from the list via SendGrid API.async removeContactsFromList(listId: string, contactEmails: string[]) { // First get the contact IDs for the emails const [searchResponse] = await this.client.request({ method: 'POST', url: '/v3/marketing/contacts/search', body: { query: `email IN (${contactEmails.map(email => `'${email}'`).join(',')}) AND CONTAINS(list_ids, '${listId}')` } }); const contacts = (searchResponse.body as { result: SendGridContact[] }).result || []; const contactIds = contacts.map(contact => contact.id).filter(id => id) as string[]; if (contactIds.length > 0) { // Remove the contacts from the list await this.client.request({ method: 'DELETE', url: `/v3/marketing/lists/${listId}/contacts`, qs: { contact_ids: contactIds.join(',') } }); } }