360 Secure SkillHub
360 安全技能中心

printful-product-builder

该 Skill 提供 Python 脚本,通过 Printful REST API 校验设计文件、映射商品变体与印刷区域,并暂存多规格商品;支持 DTG、刺绣线色模式、样机生成和仅解析/仅样机/检查等安全模式。需要 Printful API 令牌,默认不发布商品。

分类:营销
davidjackson323
davidjackson323
热度 41.11
最近更新 2026-12-02 08:05:50

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add davidjackson323/printful-product-builder
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
printful-product-builder
description
Stage multi-variant Printful products from a design using only the Printful REST API (api.printful.com). Use when asked to create, stage, or list a Printful product/listing from a design file for DTG or Embroidery, map sizes and colors to catalog variant_ids, validate print files, prepare embroidery thread colors, or generate Printful mockups.

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_library
    • PRINTFUL_STORE_ID (optional) - sent as the X-PF-Store-Id header

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-attacher to attach the design to the existing variant, and printful-listing-auditor to 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_TOKEN and optional PRINTFUL_STORE_ID from the environment.
  • Verify the store via GET /stores (or GET /stores/{id}).

2. Catalog & printfile validation

  • GET /products/{product_id} returns result.product (metadata, techniques, options, files) and result.variants (flat objects with id, size, color). The variants are NOT nested under an options object.
  • GET /mockup-generator/printfiles/{product_id}?technique=DTG (or technique=EMBROIDERY) returns available_placements (name -> label), printfiles (printfile_id, width, height, dpi, fill_mode, can_rotate) and variant_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 /files using {type, url, filename, visible}. The GET /files list endpoint has been REMOVED by Printful and returns HTTP 410 - do not call it.
  • Poll GET /files/{id} until status == "ok" so dimensions and DPI are validated before any product is created. A failed status 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 available embroidery_* placements and support three thread modes:
    • detect - POST /files/thread-colors returns up to 6 thread hex colors. The colors are returned at the TOP LEVEL of the response, not under result. 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.
  • Set the embroidery_type option to flat, 3d, or both.

4. Stage the product (POST /store/products)

  • Build sync_product with name, optional thumbnail, optional external_id, and is_ignored: true so the product stays in a safe staged/draft state.
  • Build the sync_variants array (max 100 variants per product). Each variant carries variant_id, retail_price (a STRING), sku, files (an array of {type, id} entries) and technique-specific options (an array of {id, value} objects).
  • Use --publish only with explicit owner approval; the default keeps it staged.

5. Optional mockup generation (--mockups)

  • POST /mockup-generator/create-task/{product_id} takes variant_ids, format, and a files array of {placement, image_url, position}, where position holds area_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-Reset and Retry-After headers on 429 responses, 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.