createProduct
Add new products to the Omnisend catalog by defining details such as title, description, variants, images, and pricing. Streamlines product management for targeted marketing campaigns.
Instructions
Create a new product in the Omnisend catalog. Product data can include details like title, description, variants, images, price, and more.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productData | Yes | Product data |
Implementation Reference
- src/tools/products/index.ts:68-89 (handler)MCP tool handler for createProduct: invokes API createProduct, filters response with filterProductFields, formats as MCP text content with JSON.async (args) => { try { const response = await createProduct(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:55-67 (schema)JSON Schema defining the input for createProduct tool: requires productData as object with arbitrary properties.{ additionalProperties: false, properties: { productData: { additionalProperties: true, description: "Product data", properties: {}, type: "object" } }, required: ["productData"], type: "object" },
- src/tools/products/index.ts:52-90 (registration)Registers the 'createProduct' MCP tool on the server using server.tool, specifying name, description, input schema, and handler function.server.tool( "createProduct", "Create a new product in the Omnisend catalog. Product data can include details like title, description, variants, images, price, and more.", { additionalProperties: false, properties: { productData: { additionalProperties: true, description: "Product data", properties: {}, type: "object" } }, required: ["productData"], type: "object" }, async (args) => { try { const response = await createProduct(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" }] }; } } );
- API utility function imported and called by the tool handler; performs the actual HTTP POST to /products endpoint.export const createProduct = async (productData: Partial<Product>): Promise<Product> => { try { const response = await omnisendApi.post<Product>('/products', productData); return response.data; } catch (error) { if (error instanceof Error) { throw new Error(`Error creating product: ${error.message}`); } else { throw new Error('Unknown error occurred when creating product'); } }
- src/filters/products/index.ts:2-18 (helper)Supporting utility to filter product data to a safe set of fields before returning in MCP response.export const filterProductFields = (product: any) => { return { productID: product.productID, title: product.title, status: product.status, description: product.description, currency: product.currency, price: product.price, oldPrice: product.oldPrice, productUrl: product.productUrl, imageUrl: product.imageUrl, vendor: product.vendor, variants: product.variants, createdAt: product.createdAt, updatedAt: product.updatedAt }; };