create_product
Generate custom print-on-demand products by specifying title, description, blueprint, provider, variants, and print areas using the Printify MCP Server integration.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blueprintId | Yes | Blueprint ID | |
| description | Yes | Product description | |
| printAreas | No | Print areas for the product | |
| printProviderId | Yes | Print provider ID | |
| title | Yes | Product title | |
| variants | Yes | Product variants |
Implementation Reference
- src/index.ts:268-299 (handler)The inline async handler function that executes the create_product tool logic: checks printifyClient, calls the service createProduct function, and returns formatted response.async ({ title, description, blueprintId, printProviderId, variants, printAreas }): Promise<{ content: any[], isError?: boolean }> => { // Import the printify products service const { createProduct } = await import('./services/printify-products.js'); // Check if client is initialized if (!printifyClient) { return { content: [{ type: "text", text: "Printify API client is not initialized. The PRINTIFY_API_KEY environment variable may not be set." }], isError: true }; } // Call the service const result = await createProduct(printifyClient, { title, description, blueprintId, printProviderId, variants, printAreas }); // Return the result if (result.success) { return result.response as { content: any[], isError?: boolean }; } else { return result.errorResponse as { content: any[], isError: boolean }; } }
- src/index.ts:253-267 (schema)Zod input schema defining parameters for the create_product tool.{ title: z.string().describe("Product title"), description: z.string().describe("Product description"), blueprintId: z.number().describe("Blueprint ID"), printProviderId: z.number().describe("Print provider ID"), variants: z.array(z.object({ variantId: z.number().describe("Variant ID"), price: z.number().describe("Price in cents (e.g., 1999 for $19.99)"), isEnabled: z.boolean().optional().default(true).describe("Whether the variant is enabled") })).describe("Product variants"), printAreas: z.record(z.string(), z.object({ position: z.string().describe("Print position (e.g., 'front', 'back')"), imageId: z.string().describe("Image ID from Printify uploads") })).optional().describe("Print areas for the product") },
- src/index.ts:251-300 (registration)MCP server.tool registration for the 'create_product' tool, including schema and handler.server.tool( "create_product", { title: z.string().describe("Product title"), description: z.string().describe("Product description"), blueprintId: z.number().describe("Blueprint ID"), printProviderId: z.number().describe("Print provider ID"), variants: z.array(z.object({ variantId: z.number().describe("Variant ID"), price: z.number().describe("Price in cents (e.g., 1999 for $19.99)"), isEnabled: z.boolean().optional().default(true).describe("Whether the variant is enabled") })).describe("Product variants"), printAreas: z.record(z.string(), z.object({ position: z.string().describe("Print position (e.g., 'front', 'back')"), imageId: z.string().describe("Image ID from Printify uploads") })).optional().describe("Print areas for the product") }, async ({ title, description, blueprintId, printProviderId, variants, printAreas }): Promise<{ content: any[], isError?: boolean }> => { // Import the printify products service const { createProduct } = await import('./services/printify-products.js'); // Check if client is initialized if (!printifyClient) { return { content: [{ type: "text", text: "Printify API client is not initialized. The PRINTIFY_API_KEY environment variable may not be set." }], isError: true }; } // Call the service const result = await createProduct(printifyClient, { title, description, blueprintId, printProviderId, variants, printAreas }); // Return the result if (result.success) { return result.response as { content: any[], isError?: boolean }; } else { return result.errorResponse as { content: any[], isError: boolean }; } } );
- Helper service function createProduct that wraps the API call with validation, error handling, and standardized response format.export async function createProduct( printifyClient: PrintifyAPI, productData: { title: string; description: string; blueprintId: number; printProviderId: number; variants: Array<{ variantId: number; price: number; isEnabled?: boolean; }>; printAreas?: Record<string, { position: string; imageId: string; }>; } ) { try { // Validate shop is selected const currentShop = printifyClient.getCurrentShop(); if (!currentShop) { throw new Error('No shop is currently selected. Use the list-shops and switch-shop tools to select a shop.'); } // Create product const product = await printifyClient.createProduct(productData); return { success: true, product, response: formatSuccessResponse( 'Product Created Successfully', { ProductId: product.id, Title: product.title, Shop: currentShop }, `You can now publish this product using the publish-product tool.` ) }; } catch (error: any) { console.error('Error creating product:', error); return { success: false, error, errorResponse: formatErrorResponse( error, 'Create Product', { Title: productData.title, BlueprintId: productData.blueprintId, PrintProviderId: productData.printProviderId, VariantsCount: productData.variants.length, Shop: printifyClient.getCurrentShop() }, [ 'Check that the blueprint ID is valid', 'Check that the print provider ID is valid', 'Check that the variant IDs are valid', 'Ensure your Printify account is properly connected', 'Make sure you have selected a shop' ] ) }; } }
- src/printify-api.ts:203-295 (helper)Low-level PrintifyAPI class method that formats request data and calls the Printify SDK to create the product.async createProduct(productData: any) { if (!this.shopId) { throw new Error('Shop ID is not set. Call setShopId() first.'); } try { // Format the product data to match the API's expected format const formattedData: any = { title: productData.title, description: productData.description, blueprint_id: parseInt(productData.blueprint_id || productData.blueprintId), print_provider_id: parseInt(productData.print_provider_id || productData.printProviderId), variants: [], print_areas: [] }; // Format variants if (productData.variants && Array.isArray(productData.variants)) { formattedData.variants = productData.variants.map((variant: any) => { return { id: parseInt(variant.id || variant.variantId), price: parseInt(variant.price), is_enabled: variant.isEnabled !== false }; }); } // Log the raw data received console.log('Raw product data received:', JSON.stringify(productData, null, 2)); // Format print areas - handle both print_areas and printAreas formats const printAreasData = productData.print_areas || productData.printAreas; if (printAreasData) { // Get all variant IDs from the variants array const variantIds = formattedData.variants.map((v: any) => v.id); // Create a print area entry with all variants const printAreaEntry: any = { variant_ids: variantIds, placeholders: [] }; // Add placeholders for each position (front, back, etc.) for (const key in printAreasData) { const area = printAreasData[key]; printAreaEntry.placeholders.push({ position: area.position, images: [ { id: area.image_id || area.imageId, x: 0.5, y: 0.5, scale: 1, angle: 0 } ] }); } // Add the print area entry to the formatted data formattedData.print_areas.push(printAreaEntry); } console.log(`Creating product with shop ID: ${this.shopId}`); console.log('Formatted product data:', JSON.stringify(formattedData, null, 2)); try { // Use the products.create method with the formatted data const result = await this.client.products.create(formattedData); return result; } catch (error: any) { // Add the formatted data to the error object for better debugging error.formattedData = formattedData; // Log the full error response console.error('Full error response:', error); // If there's a response object, extract and log the full response data if (error.response) { console.error('Response status:', error.response.status); console.error('Response data:', JSON.stringify(error.response.data, null, 2)); // Add the full response data to the error object error.fullResponseData = error.response.data; } throw error; } } catch (error) { console.error('Error creating product:', error); throw this.enhanceError(error, productData); } }