update_product
Modify product details in CS-Cart stores by updating name, price, stock, description, categories, or status using product ID.
Instructions
Update an existing product
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| product_id | Yes | Product ID to update | |
| product | No | Product name | |
| price | No | Product price | |
| category_ids | No | Array of category IDs | |
| description | No | Product description | |
| full_description | No | Full product description | |
| status | No | Product status (A=Active, D=Disabled, H=Hidden) | |
| amount | No | Product quantity in stock | |
| weight | No | Product weight | |
| shipping_freight | No | Shipping cost |
Implementation Reference
- src/index.js:469-473 (handler)Executes the update_product tool by sending a PUT request to the CS-Cart API with the provided product data, excluding product_id which is used in the URL.async updateProduct(args) { const { product_id, ...productData } = args; const result = await this.makeRequest('PUT', `/products/${product_id}`, productData); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.js:142-189 (schema)Input schema defining the parameters for the update_product tool, requiring product_id and allowing updates to various product fields.inputSchema: { type: 'object', properties: { product_id: { type: 'number', description: 'Product ID to update', }, product: { type: 'string', description: 'Product name', }, price: { type: 'number', description: 'Product price', }, category_ids: { type: 'array', items: { type: 'number' }, description: 'Array of category IDs', }, description: { type: 'string', description: 'Product description', }, full_description: { type: 'string', description: 'Full product description', }, status: { type: 'string', description: 'Product status (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, amount: { type: 'number', description: 'Product quantity in stock', }, weight: { type: 'number', description: 'Product weight', }, shipping_freight: { type: 'number', description: 'Shipping cost', }, }, required: ['product_id'], },
- src/index.js:396-397 (registration)Switch case in the CallToolRequestSchema handler that routes 'update_product' calls to the updateProduct method.case 'update_product': return await this.updateProduct(args);
- src/index.js:139-190 (registration)Tool registration in the ListToolsRequestSchema response, defining name, description, and input schema for update_product.{ name: 'update_product', description: 'Update an existing product', inputSchema: { type: 'object', properties: { product_id: { type: 'number', description: 'Product ID to update', }, product: { type: 'string', description: 'Product name', }, price: { type: 'number', description: 'Product price', }, category_ids: { type: 'array', items: { type: 'number' }, description: 'Array of category IDs', }, description: { type: 'string', description: 'Product description', }, full_description: { type: 'string', description: 'Full product description', }, status: { type: 'string', description: 'Product status (A=Active, D=Disabled, H=Hidden)', enum: ['A', 'D', 'H'], }, amount: { type: 'number', description: 'Product quantity in stock', }, weight: { type: 'number', description: 'Product weight', }, shipping_freight: { type: 'number', description: 'Shipping cost', }, }, required: ['product_id'], }, },
- src/index.js:424-440 (helper)Helper method used by the updateProduct handler to make authenticated API requests to the CS-Cart server.async makeRequest(method, endpoint, data = null) { const config = { method, url: `${process.env.CSCART_API_URL}${endpoint}`, headers: { 'Content-Type': 'application/json', 'Authorization': `Basic ${Buffer.from(`${process.env.CSCART_API_EMAIL}:${process.env.CSCART_API_KEY}`).toString('base64')}`, }, }; if (data) { config.data = data; } const response = await axios(config); return response.data; }