createContact
Add or update a contact in Omnisend with email, phone, subscription status, and custom properties to streamline audience management.
Instructions
Create or update a contact in Omnisend. Contact data can include identifiers (email, phone), personal information, subscription status, and custom properties.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactData | Yes | Contact data |
Implementation Reference
- src/tools/contacts/index.ts:68-89 (handler)The handler function that executes the createContact tool. It calls the createOrUpdateContact helper, filters the response with filterContactFields, and returns JSON stringified result or error.async (args) => { try { const response = await createOrUpdateContact(args.contactData); // Filter contact data to include only defined fields const filteredContact = filterContactFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredContact, null, 2) } ] }; } catch (error) { if (error instanceof Error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } return { content: [{ type: "text", text: "An unknown error occurred" }] }; } }
- src/tools/contacts/index.ts:55-67 (schema)JSON Schema defining the input parameters for the createContact tool: requires contactData object.{ additionalProperties: false, properties: { contactData: { additionalProperties: true, description: "Contact data", properties: {}, type: "object" } }, required: ["contactData"], type: "object" },
- src/tools/contacts/index.ts:52-90 (registration)Full registration of the createContact tool with the MCP server, including name, description, input schema, and handler function.server.tool( "createContact", "Create or update a contact in Omnisend. Contact data can include identifiers (email, phone), personal information, subscription status, and custom properties.", { additionalProperties: false, properties: { contactData: { additionalProperties: true, description: "Contact data", properties: {}, type: "object" } }, required: ["contactData"], type: "object" }, async (args) => { try { const response = await createOrUpdateContact(args.contactData); // Filter contact data to include only defined fields const filteredContact = filterContactFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredContact, null, 2) } ] }; } catch (error) { if (error instanceof Error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } return { content: [{ type: "text", text: "An unknown error occurred" }] }; } } );
- Helper function that makes the actual POST request to Omnisend API /contacts endpoint to create or update the contact.export const createOrUpdateContact = async (contactData: Partial<Contact>): Promise<Contact> => { try { const response = await omnisendApi.post<Contact>('/contacts', contactData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error creating contact: ${error.message}`); } else { throw new Error('Unknown error occurred when creating contact'); } } };
- src/filters/contacts/index.ts:2-21 (helper)Utility function to filter and select specific fields from the contact response object.export const filterContactFields = (contact: any) => { return { contactID: contact.contactID, email: contact.email, phone: contact.phone, firstName: contact.firstName, lastName: contact.lastName, status: contact.status, tags: contact.tags, identifiers: contact.identifiers, createdAt: contact.createdAt, updatedAt: contact.updatedAt, // Include added fields country: contact.country, state: contact.state, city: contact.city, gender: contact.gender, birthdate: contact.birthdate }; };