addBulkContactToList
Add multiple contacts to a Mailmodo list in a single API call, including their email, name, phone, address, and other custom fields.
Instructions
Add Many Contact to a list in single API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| listName | Yes | ||
| values | Yes |
Implementation Reference
- src/server.ts:197-241 (registration)Tool registration for addBulkContactToList using server.tool(). Defines schema and handler callback.
server.tool( "addBulkContactToList", "Add Many Contact to a list in single API", { listName: z.string(), values: z.array(z.object({ email: z.string(), data: contactPropertiesSchema.optional(), created_at: datetimeSchema.optional(), last_click: datetimeSchema.optional(), last_open: datetimeSchema.optional(), timezone: z .string() .regex( timezoneRegex, { message: "Must be a valid region-format timezone string" } ) .optional(), })) }, async (params) => { try { const respone = await bulkAddContactToList(mmApiKey,params); // 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.listId != '' ?`Successfully added '${params.values.length}' contacts to 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 send event", }], isError: true }; } } ); - src/server.ts:217-241 (handler)Handler function that calls bulkAddContactToList API and returns success/error response.
async (params) => { try { const respone = await bulkAddContactToList(mmApiKey,params); // 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.listId != '' ?`Successfully added '${params.values.length}' contacts to 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 send event", }], isError: true }; } } ); - src/apicalls/contactManagement.ts:44-75 (handler)Core API function bulkAddContactToList that makes HTTP POST to Mailmodo /addToList/batch endpoint.
export async function bulkAddContactToList( mmApiKey: string, payload: BulkMailmodoContact ): Promise<AddBatchContactToListResponse> { const allHaveEmails = payload.values.every(user => typeof user.email === 'string' && user.email.trim() !== ''); if (!allHaveEmails || !payload.listName) { throw new Error('Email and listname are required fields'); } try { const response = await axios.post<AddBatchContactToListResponse>( 'https://api.mailmodo.com/api/v1/addToList/batch', { ...payload, }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { return {listId: ''} } throw new Error('An unexpected error occurred'); } } - src/server.ts:200-216 (schema)Input schema for addBulkContactToList: listName (string) and values (array of contacts with email, data, timestamps, timezone).
{ listName: z.string(), values: z.array(z.object({ email: z.string(), data: contactPropertiesSchema.optional(), created_at: datetimeSchema.optional(), last_click: datetimeSchema.optional(), last_open: datetimeSchema.optional(), timezone: z .string() .regex( timezoneRegex, { message: "Must be a valid region-format timezone string" } ) .optional(), })) }, - src/types/addContactsTypes.ts:50-53 (schema)BulkMailmodoContact interface and AddBatchContactToListResponse interface used by the handler.
export interface BulkMailmodoContact{ listName: string; values: MailmodoContactWithoutList[] }