update_segment
Modify an existing segment's name or query criteria to refine audience targeting and contact organization in SendGrid email marketing campaigns.
Instructions
Update an existing segment's name or query criteria
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | New name for the segment | |
| query_dsl | No | New query criteria for the segment (JSON string) | |
| segment_id | Yes | ID of the segment to update |
Implementation Reference
- src/tools/contacts.ts:494-520 (handler)The main handler function that implements the update_segment tool logic: checks read-only mode, prepares update data for name and/or query_dsl, parses JSON if provided, makes PATCH request to SendGrid API to update the segment.handler: async ({ segment_id, name, query_dsl }: { segment_id: string; name?: string; query_dsl?: string }): Promise<ToolResult> => { const readOnlyCheck = checkReadOnlyMode(); if (readOnlyCheck.blocked) { return { content: [{ type: "text", text: readOnlyCheck.message! }] }; } const updateData: any = {}; if (name) updateData.name = name; if (query_dsl) { try { updateData.query_dsl = JSON.parse(query_dsl); } catch (error) { return { content: [{ type: "text", text: "Error: query_dsl must be valid JSON. Please provide a properly formatted query." }] }; } } if (Object.keys(updateData).length === 0) { return { content: [{ type: "text", text: "Error: Please provide either 'name' or 'query_dsl' to update." }] }; } const result = await makeRequest(`https://api.sendgrid.com/v3/marketing/segments/2.0/${segment_id}`, { method: "PATCH", body: JSON.stringify(updateData), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },
- src/tools/contacts.ts:488-492 (schema)Zod input schema defining parameters for update_segment: segment_id (required string), optional name and query_dsl (strings).inputSchema: { segment_id: z.string().describe("ID of the segment to update"), name: z.string().optional().describe("New name for the segment"), query_dsl: z.string().optional().describe("New query criteria for the segment (JSON string)"), },
- src/tools/contacts.ts:484-520 (registration)The registration of the update_segment tool as part of the contactTools object export, including config and handler.update_segment: { config: { title: "Update Segment", description: "Update an existing segment's name or query criteria", inputSchema: { segment_id: z.string().describe("ID of the segment to update"), name: z.string().optional().describe("New name for the segment"), query_dsl: z.string().optional().describe("New query criteria for the segment (JSON string)"), }, }, handler: async ({ segment_id, name, query_dsl }: { segment_id: string; name?: string; query_dsl?: string }): Promise<ToolResult> => { const readOnlyCheck = checkReadOnlyMode(); if (readOnlyCheck.blocked) { return { content: [{ type: "text", text: readOnlyCheck.message! }] }; } const updateData: any = {}; if (name) updateData.name = name; if (query_dsl) { try { updateData.query_dsl = JSON.parse(query_dsl); } catch (error) { return { content: [{ type: "text", text: "Error: query_dsl must be valid JSON. Please provide a properly formatted query." }] }; } } if (Object.keys(updateData).length === 0) { return { content: [{ type: "text", text: "Error: Please provide either 'name' or 'query_dsl' to update." }] }; } const result = await makeRequest(`https://api.sendgrid.com/v3/marketing/segments/2.0/${segment_id}`, { method: "PATCH", body: JSON.stringify(updateData), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },