removeContactFromList
Remove a specific contact from a contact list by providing the contact's email and the list name.
Instructions
Remove a particular contact from the contact list
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | |||
| listName | Yes |
Implementation Reference
- src/server.ts:339-371 (registration)Registration of the 'removeContactFromList' tool via server.tool(), with Zod schema for email and listName, and handler that calls the API function.
server.tool( "removeContactFromList", "Remove a particular contact from the contact list", { email: z.string(), listName: z.string(), }, async (params) => { try { const respone = await removeContactFromList(mmApiKey, params.email, params.listName); // Here you would typically integrate with your event sending system // For example: eventBus.emit(eventName, eventData) // For demonstration, we'll just return a success message return { content: [{ type: "text", text: respone.message ?`Successfully reomved '${params.email} from the list ${params.listName} with message ${respone.message}.`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to delete", }], isError: true }; } } ); - Type definition for RemoveContactFromListResponse with a message field.
export interface RemoveContactFromListResponse { message: string; } - Core handler function removeContactFromList that makes an axios POST request to the Mailmodo API endpoint to remove a contact from a list by email and listName.
export const removeContactFromList = async ( mmApiKey: string, email: string, listName: string ): Promise<RemoveContactFromListResponse> => { try { const response = await axios.post<RemoveContactFromListResponse>( 'https://api.mailmodo.com/api/v1/removeFromList', { email, listName }, { headers: { 'Accept': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { if(error.status === 400){ return {message: "This contact doesn't exists in list"}; } throw error; } throw new Error('Failed to remove contact from list'); } }; - src/server.ts:6-6 (helper)Import of removeContactFromList from contactManagement module into server.ts.
import { addContactToList, bulkAddContactToList, deleteContact, getAllContactLists, getContactDetails, removeContactFromList, resubscribeContact, unsubscribeContact } from "./apicalls/contactManagement"; - Import of RemoveContactFromListResponse type from types/addContactsTypes.
import { AddBatchContactToListResponse, AddContactToListResponse, BulkMailmodoContact, MailmodoContact, GetContactListsResponse, RemoveContactFromListResponse } from "types/addContactsTypes";