printful-product-builder
Latest: v1.0.0
Version 1.0.0 introduces a workflow for safely staging multi-variant Printful products using the Printful REST API.
- Adds catalog variant mapping and print-file validation for DTG and embroidery.
- Supports embroidery thread-color options and optional mockup generation.
- Keeps products staged by default, with safeguards for store type and publishing.
- Provides resolve-only, mockups-only, and product inspection modes.
Printful Product Builder
Stages a complete, multi-variant Printful product from a design file using ONLY the Printful REST API (https://api.printful.com). No Etsy API calls.
Companion script
scripts/build_printful_product.py - the executable implementation of this workflow.
Requirements
- Python 3.9+ (standard library only, no third-party packages).
- Environment:
PRINTFUL_API_TOKEN(required) - scopes:sync_products,file_libraryPRINTFUL_STORE_ID(optional) - sent as theX-PF-Store-Idheader
IMPORTANT - store type decides which skill applies
POST /store/products works ONLY on a native (Manual order / API) store. On an
Etsy or other ecommerce integration store, Printful answers HTTP 400:
"This API endpoint applies only to Printful stores based on the Manual Order / API
platform."
- native store - use this skill to create a new product.
- integration store (etsy, shopify, ...) - the listing already exists in the shop
and Printful mirrors it as a Sync Product. Use
printful-design-attacherto attach the design to the existing variant, andprintful-listing-auditorto review the store.
For general account work (orders, webhooks, tax, shipping, warehouse, reports,
catalog browsing) use the printful-management skill. It covers a much wider API
surface, but it has no dry-run and no write gate - for anything that stages or
publishes, prefer this skill and the attacher, which preview the exact payload
before writing.
The script checks GET /stores on startup, warns clearly when the store type is not
native, and refuses to stage unless you pass --allow-non-native-store.
Workflow
1. Authentication & store context
- Load
PRINTFUL_API_TOKENand optionalPRINTFUL_STORE_IDfrom the environment. - Verify the store via
GET /stores(orGET /stores/{id}).
2. Catalog & printfile validation
GET /products/{product_id}returnsresult.product(metadata,techniques,options,files) andresult.variants(flat objects withid,size,color). The variants are NOT nested under anoptionsobject.GET /mockup-generator/printfiles/{product_id}?technique=DTG(ortechnique=EMBROIDERY) returnsavailable_placements(name -> label),printfiles(printfile_id, width, height, dpi, fill_mode, can_rotate) andvariant_printfiles(variant_id -> {placement: printfile_id}).- Map the requested sizes and colors to exact catalog
variant_ids and report the print area dimensions and minimum DPI for each placement. - A placement name ("front", "back", "embroidery_chest_left") is NOT the same as the sync-file type ("default", "back", "embroidery_chest_left"); the script keeps them separate.
3. File library & embroidery thread color preparation
- Register the design with
POST /filesusing{type, url, filename, visible}. TheGET /fileslist endpoint has been REMOVED by Printful and returns HTTP 410 - do not call it. - Poll
GET /files/{id}untilstatus == "ok"so dimensions and DPI are validated before any product is created. Afailedstatus means Printful could not process the image - stop rather than create a product with a broken file. - Append a cache-busting query parameter (--cache-bust) when the file at a reused URL may have been modified.
- For
EMBROIDERY, inspect the availableembroidery_*placements and support three thread modes:- detect -
POST /files/thread-colorsreturns up to 6 thread hex colors. The colors are returned at the TOP LEVEL of the response, not underresult. Map them to the placement's matching option id (thread_colors_chest_left,thread_colors, ...). - auto - set
{"id": "auto_thread_color", "value": true}in the file options. - full_color - set
{"id": "full_color", "value": true}in the file options for Unlimited Color embroidery.
- detect -
- Set the
embroidery_typeoption toflat,3d, orboth.
4. Stage the product (POST /store/products)
- Build
sync_productwithname, optionalthumbnail, optionalexternal_id, andis_ignored: trueso the product stays in a safe staged/draft state. - Build the
sync_variantsarray (max 100 variants per product). Each variant carriesvariant_id,retail_price(a STRING),sku,files(an array of{type, id}entries) and technique-specificoptions(an array of{id, value}objects). - Use
--publishonly with explicit owner approval; the default keeps it staged.
5. Optional mockup generation (--mockups)
POST /mockup-generator/create-task/{product_id}takesvariant_ids,format, and afilesarray of{placement, image_url, position}, wherepositionholdsarea_width,area_height,width,height,top,left.- Wait at least 10 seconds, then poll
GET /mockup-generator/task?task_key={key}. - Download the resulting mockup images locally before their 72-hour URL expiration.
6. Rate limiting
- Honor
X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-ResetandRetry-Afterheaders on429responses, especially on the Mockup Generator endpoint (limited to 2-10 requests per minute). The client backs off with jittered exponential sleep and retries up to 5 times.
Modes
--resolve-only- validate the catalog mapping and print requirements, then exit without touching the file library or the store. This is the safe first step.--mockups-only- generate and download mockups without staging a product (mockups do not require a product).--inspect <id>- print a summary of an existing product/variant and exit.
Usage
# DTG tee
python scripts/build_printful_product.py \
--product-id 71 --technique DTG \
--file-url https://example.com/design.png --name "My Design" \
--price 24.99 --sizes S,M,L --colors Black,White --mockups
# Embroidery cap, detected thread colors
python scripts/build_printful_product.py \
--product-id 71 --technique EMBROIDERY \
--file-url https://example.com/logo.png --name "Logo Cap" --price 32.00 \
--sizes OS --colors Black --embroidery-type flat --thread-mode detect \
--placement embroidery_chest_left
# Validate the mapping without writing anything
python scripts/build_printful_product.py \
--product-id 71 --technique DTG --sizes S,M,L --colors Black --resolve-only
The script prints a JSON summary (product id, variants, file id, options, downloaded mockup paths) on stdout and exits non-zero on any validation failure.
Guardrails
- Never publish (is_ignored=false) without the owner's explicit approval.
- Never write to a store that is not
native; warn and stop instead. - Register and validate the design file BEFORE creating the product.
- Keep the token in the environment; never print it or write it into artifacts.
