sendEvent
Track customer behavior by sending events to Omnisend to trigger marketing automations and analyze interactions.
Instructions
Send a customer event to Omnisend. Events are used to track customer behavior and can trigger automations. Can be custom events or predefined system events.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/events/index.ts:46-67 (handler)MCP tool handler for 'sendEvent'. Calls the core sendEvent API function with provided args.eventData, filters the Event response using filterEventFields, formats as pretty JSON text content, and handles errors by returning error messages.async (args) => { try { const response = await sendEvent(args.eventData); // Filter event data to include only defined fields const filteredEvent = filterEventFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredEvent, 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/events/index.ts:10-44 (schema)JSON Schema for sendEvent tool input. Defines structure of eventData object, requiring eventName and contact (with optional subfields), allowing optional eventTime, eventVersion, and arbitrary properties.{ additionalProperties: false, properties: { eventData: { additionalProperties: false, description: "Event data", properties: { eventName: { description: "Event name", type: "string" }, eventTime: { description: "Event time in RFC3339 format", type: "string" }, eventVersion: { description: "Event version", type: "string" }, contact: { additionalProperties: true, description: "Contact information", properties: { contactID: { type: "string" }, email: { type: "string" }, firstName: { type: "string" }, lastName: { type: "string" }, phone: { type: "string" } }, type: "object" }, properties: { additionalProperties: true, description: "Additional event properties", properties: {}, type: "object" } }, required: ["eventName", "contact"], type: "object" } }, required: ["eventData"], type: "object"
- src/tools/events/index.ts:7-68 (registration)Registration of the sendEvent tool using server.tool(name, description, schema, handler). Part of the registerEventsTools function called by the main server initialization.server.tool( "sendEvent", "Send a customer event to Omnisend. Events are used to track customer behavior and can trigger automations. Can be custom events or predefined system events.", { additionalProperties: false, properties: { eventData: { additionalProperties: false, description: "Event data", properties: { eventName: { description: "Event name", type: "string" }, eventTime: { description: "Event time in RFC3339 format", type: "string" }, eventVersion: { description: "Event version", type: "string" }, contact: { additionalProperties: true, description: "Contact information", properties: { contactID: { type: "string" }, email: { type: "string" }, firstName: { type: "string" }, lastName: { type: "string" }, phone: { type: "string" } }, type: "object" }, properties: { additionalProperties: true, description: "Additional event properties", properties: {}, type: "object" } }, required: ["eventName", "contact"], type: "object" } }, required: ["eventData"], type: "object" }, async (args) => { try { const response = await sendEvent(args.eventData); // Filter event data to include only defined fields const filteredEvent = filterEventFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredEvent, 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" }] }; } } );
- Core helper function sendEvent that performs HTTP POST to Omnisend API /events endpoint with Partial<Event> data, returns full Event response or throws detailed error.export const sendEvent = async (eventData: Partial<Event>): Promise<Event> => { try { const response = await omnisendApi.post<Event>('/events', eventData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error sending event: ${error.message}`); } else { throw new Error('Unknown error occurred when sending event'); } } };