replaceProduct
Overwrite an existing product's information by replacing it entirely with new data using the specified product ID. Ideal for comprehensive updates in the Omnisend marketing platform.
Instructions
Replace an existing product with new data. This completely overwrites the product information rather than updating specific fields.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productData | Yes | Product data | |
| productId | Yes | Product ID |
Implementation Reference
- src/tools/products/index.ts:146-167 (handler)Handler function for the replaceProduct MCP tool: calls the API replaceProduct helper, applies filtering, and returns formatted JSON text response.async (args) => { try { const response = await replaceProduct(args.productId, args.productData); // Filter product data to include only defined fields const filteredProduct = filterProductFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredProduct, 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/products/index.ts:132-144 (schema)JSON Schema defining the input parameters for the replaceProduct tool: productId (required string) and productData (required object).{ additionalProperties: false, properties: { productId: { description: "Product ID", type: "string" }, productData: { additionalProperties: true, description: "Product data in the same structure as returned by getProduct", properties: {}, type: "object" } }, required: ["productId", "productData"], type: "object"
- src/tools/products/index.ts:129-168 (registration)Registration of the replaceProduct tool on the MCP server using server.tool() with name, description, schema, and handler.server.tool( "replaceProduct", "Replace an existing product with new data. IMPORTANT: You must first get the product using getProduct and preserve the returned structure when replacing. The replace request requires the same structure as returned by the GET method, with only your desired changes applied.", { additionalProperties: false, properties: { productId: { description: "Product ID", type: "string" }, productData: { additionalProperties: true, description: "Product data in the same structure as returned by getProduct", properties: {}, type: "object" } }, required: ["productId", "productData"], type: "object" }, async (args) => { try { const response = await replaceProduct(args.productId, args.productData); // Filter product data to include only defined fields const filteredProduct = filterProductFields(response); return { content: [ { type: "text", text: JSON.stringify(filteredProduct, 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 implementing the Omnisend API call to replace (PUT) a product by ID.export const replaceProduct = async (productId: string, productData: Partial<Product>): Promise<Product> => { try { const response = await omnisendApi.put<Product>(`/products/${productId}`, productData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error replacing product: ${error.message}`); } else { throw new Error('Unknown error occurred when replacing product'); } }
- src/index.ts:32-32 (registration)High-level registration call that includes the replaceProduct tool among products tools on the main MCP server.registerProductsTools(server);