Skip to main content
Glama

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
NameRequiredDescriptionDefault
contactDataYesContact data

Implementation Reference

  • 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" }] }; } }
  • 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" },
  • 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'); } } };
  • 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 }; };

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/plutzilla/omnisend-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server