create_product
Create a print-on-demand product on Printify by specifying title, description, blueprint, print provider, variants, and print areas.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Product title | |
| description | Yes | Product description | |
| blueprintId | Yes | Blueprint ID | |
| printProviderId | Yes | Print provider ID | |
| variants | Yes | Product variants | |
| printAreas | No | Print areas for the product |
Implementation Reference
- src/index.ts:250-300 (registration)MCP tool registration for 'create_product' — defines the tool name, Zod schema for input validation (title, description, blueprintId, printProviderId, variants, optional printAreas), and the handler that calls the service layer.
// Create product tool 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 }; } } ); - Business logic handler for create_product — validates shop selection, calls printifyClient.createProduct(), formats success/error responses.
/** * Create a product in Printify */ 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' ] ) }; } } - Type signature / input schema for the createProduct service function — defines the productData parameter shape (title, description, blueprintId, printProviderId, variants, printAreas).
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; }>; } - src/printify-api.ts:202-295 (helper)Low-level API method createProduct on PrintifyAPI class — formats data (converts camelCase to snake_case), handles print areas and variants mapping, calls printify-sdk-js client.products.create().
// Create a new 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); } }