updateContact
Modify an existing contact's details in Omnisend by applying specific changes to the contact's stored information.
Instructions
Update an existing contact's information. IMPORTANT: You must first get the contact using getContact and preserve the returned structure when updating. The update request requires the same structure as returned by the GET method, with only your desired changes applied.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/contacts/index.ts:146-167 (handler)The handler function that executes the updateContact tool. It calls the underlying updateContact API function with contactId and contactData, filters the response using filterContactFields, and returns the JSON stringified result or error message.async (args) => { try { const response = await updateContact(args.contactId, 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:132-144 (schema)Input schema for the updateContact tool, defining parameters contactId (string) and contactData (object).{ additionalProperties: false, properties: { contactId: { description: "Contact ID", type: "string" }, contactData: { additionalProperties: true, description: "Contact data in the same structure as returned by getContact", properties: {}, type: "object" } }, required: ["contactId", "contactData"], type: "object"
- src/tools/contacts/index.ts:129-168 (registration)Registration of the updateContact tool on the MCP server, including the tool name, description, input schema, and handler function.server.tool( "updateContact", "Update an existing contact's information. IMPORTANT: You must first get the contact using getContact and preserve the returned structure when updating. The update request requires the same structure as returned by the GET method, with only your desired changes applied.", { additionalProperties: false, properties: { contactId: { description: "Contact ID", type: "string" }, contactData: { additionalProperties: true, description: "Contact data in the same structure as returned by getContact", properties: {}, type: "object" } }, required: ["contactId", "contactData"], type: "object" }, async (args) => { try { const response = await updateContact(args.contactId, 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 PATCH API call to Omnisend to update a specific contact by ID.export const updateContact = async (contactId: string, contactData: Partial<Contact>): Promise<Contact> => { try { const response = await omnisendApi.patch<Contact>(`/contacts/${contactId}`, contactData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error updating contact: ${error.message}`); } else { throw new Error('Unknown error occurred when updating contact'); } } };