update_profile
Modify customer profile details in Klaviyo by updating fields like email, phone number, first name, last name, and custom properties using the profile ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| No | Email address of the profile | ||
| external_id | No | External ID for the profile | |
| first_name | No | First name of the profile | |
| id | Yes | ID of the profile to update | |
| last_name | No | Last name of the profile | |
| phone_number | No | Phone number of the profile | |
| properties | No | Additional properties for the profile |
Implementation Reference
- src/tools/profiles.js:111-146 (handler)The main handler function for the 'update_profile' tool. It extracts the profile ID, builds attributes from input parameters, constructs a PATCH payload, calls klaviyoClient.patch to update the profile, and returns the result or error.async (params) => { try { const { id, ...rest } = params; const attributes = {}; // Add all provided fields to attributes for (const [key, value] of Object.entries(rest)) { if (value !== undefined && key !== 'properties') { attributes[key] = value; } } // Add properties if provided if (params.properties) { attributes.properties = params.properties; } const payload = { data: { type: "profile", id, attributes } }; const result = await klaviyoClient.patch(`/profiles/${id}/`, payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error updating profile: ${error.message}` }], isError: true }; } },
- src/tools/profiles.js:102-110 (schema)Zod schema defining the input parameters for the 'update_profile' tool, including required profile ID and optional fields like email, phone, names, and custom properties.{ id: z.string().describe("ID of the profile to update"), email: z.string().email().optional().describe("Email address of the profile"), phone_number: z.string().optional().describe("Phone number of the profile"), external_id: z.string().optional().describe("External ID for the profile"), first_name: z.string().optional().describe("First name of the profile"), last_name: z.string().optional().describe("Last name of the profile"), properties: z.record(z.any()).optional().describe("Additional properties for the profile") },
- src/tools/profiles.js:100-148 (registration)The server.tool call that registers the 'update_profile' tool with its name, input schema, handler function, and description within the registerProfileTools function.server.tool( "update_profile", { id: z.string().describe("ID of the profile to update"), email: z.string().email().optional().describe("Email address of the profile"), phone_number: z.string().optional().describe("Phone number of the profile"), external_id: z.string().optional().describe("External ID for the profile"), first_name: z.string().optional().describe("First name of the profile"), last_name: z.string().optional().describe("Last name of the profile"), properties: z.record(z.any()).optional().describe("Additional properties for the profile") }, async (params) => { try { const { id, ...rest } = params; const attributes = {}; // Add all provided fields to attributes for (const [key, value] of Object.entries(rest)) { if (value !== undefined && key !== 'properties') { attributes[key] = value; } } // Add properties if provided if (params.properties) { attributes.properties = params.properties; } const payload = { data: { type: "profile", id, attributes } }; const result = await klaviyoClient.patch(`/profiles/${id}/`, payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error updating profile: ${error.message}` }], isError: true }; } }, { description: "Update an existing profile in Klaviyo" } );
- src/server.js:32-32 (registration)Invocation of registerProfileTools(server) which registers the 'update_profile' tool along with other profile-related tools.registerProfileTools(server);
- src/tools/profiles.js:2-2 (helper)Import of klaviyoClient utility used by the update_profile handler for making the PATCH request to update profiles.import * as klaviyoClient from '../klaviyo-client.js';