updateCategory
Modify an existing product category in Omnisend by updating its details while maintaining the original structure obtained from getCategory.
Instructions
Update an existing product category. IMPORTANT: You must first get the category using getCategory and preserve the returned structure when updating.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/categories/index.ts:123-162 (registration)Registers the updateCategory MCP tool with schema, description, and thin wrapper handler that calls core update function and formats response.server.tool( "updateCategory", "Update an existing product category. IMPORTANT: You must first get the category using getCategory and preserve the returned structure when updating.", { additionalProperties: false, properties: { categoryId: { description: "Category ID", type: "string" }, categoryData: { additionalProperties: true, description: "Category data in the same structure as returned by getCategory", properties: {}, type: "object" } }, required: ["categoryId", "categoryData"], type: "object" }, async (args) => { try { const response = await updateCategory(args.categoryId, args.categoryData); // Filter category data to include only defined fields const filteredCategory = filterCategoryFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredCategory, 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 handler function for updating a category via Omnisend API PUT request to /product-categories/{categoryId}.export const updateCategory = async (categoryId: string, categoryData: Partial<ProductCategory>): Promise<ProductCategory> => { try { const response = await omnisendApi.put<ProductCategory>(`/product-categories/${categoryId}`, categoryData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error updating category: ${error.message}`); } else { throw new Error('Unknown error occurred when updating category'); } } };
- src/types/categories/index.ts:3-13 (schema)TypeScript interface defining the ProductCategory structure used for input/output validation in updateCategory.export interface ProductCategory { categoryID: string; title: string; handle?: string; description?: string; imageUrl?: string; categoryUrl?: string; createdAt?: string; updatedAt?: string; [key: string]: unknown; }
- src/tools/index.ts:5-5 (helper)Top-level export of the registerCategoriesTools function, which includes the updateCategory tool registration.export { registerCategoriesTools } from './categories/index.js';