360 Secure SkillHub
360 安全技能中心

printful-design-attacher

使用仅依赖标准库的 Python 脚本调用 Printful REST API,为已存在的 Sync Product 变体注册并校验设计文件,支持替换文件、生成刺绣线色选项,并在写入前预览 PUT 载荷。

分类:营销
davidjackson323
davidjackson323
热度 39.29
最近更新 2026-12-02 08:09:37

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add davidjackson323/printful-design-attacher
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
printful-design-attacher
description
Attach an existing design file to an already-listed Printful product variant using only the Printful REST API (api.printful.com). Use when a design is already listed in the shop but the print file is missing, needs replacing, or needs embroidery thread colours set. Covers Ecommerce Platform Sync API variant updates (PUT /sync/variant/{id}), file library validation, thread colour detection, and read-only inspection of a synced variant.

Printful Design Attacher

Attach a validated design file to an EXISTING Printful Sync Product variant using only the Printful REST API (https://api.printful.com). No Etsy API calls.

Use this when the listing already exists in the shop and Printful mirrors it as a Sync Product, but the print file still has to be attached or changed. To CREATE a new product instead, use printful-product-builder. For general account work (orders, webhooks, tax, shipping, warehouse, reports) use printful-management.

Companion script

scripts/attach_printful_design.py

Requirements

  • Python 3.9+ (standard library only).
  • Environment:
    • PRINTFUL_API_TOKEN (required) - scopes: sync_products, file_library
    • PRINTFUL_STORE_ID (optional) - sent as the X-PF-Store-Id header

Workflow

1. Authentication & store context

  • Load PRINTFUL_API_TOKEN and optional PRINTFUL_STORE_ID from the environment.
  • Verify the store via GET /stores. A native store means the product does not exist yet - switch to printful-product-builder. An integration store (etsy, shopify, ...) means the listing exists and this skill is the right tool.

2. Resolve the target product and variant

  • GET /sync/products/{id} returns sync_product plus sync_variants.
  • Pick the variant by --variant-id, --external-id, --size and/or --color. Report every available variant when nothing matches, so the choice is not guessed.

3. Register and validate the design

  • POST /files with {type, url, filename, visible} registers the design.
  • Poll GET /files/{id} until status == "ok" so dimensions and DPI are validated before the variant is modified. A failed status means Printful could not process the image - stop rather than attach a broken file.
  • Append a cache-busting query parameter with --cache-bust when the file at a reused URL may have changed.

4. Prepare embroidery thread colours

For EMBROIDERY, pick the placement (for example embroidery_chest_left) and choose one of three modes:

  • detect - POST /files/thread-colors returns up to 6 hex colours; map them to the placement's 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.
  • Always set embroidery_type to flat, 3d, or both.

5. Attach

  • PUT /sync/variant/{id} with the file entry ({type, id}), optional retail_price, sku, is_ignored and variant options.
  • Print the resulting variant state so the change is verifiable.

Usage

# Attach a design to an existing variant
python scripts/attach_printful_design.py --product-id 501345091 --size M --color Black \
    --file-url https://example.com/design.png --price 29.99

# Embroidery with detected thread colours
python scripts/attach_printful_design.py --variant-id 5680191910 \
    --file-url https://example.com/logo.png --price 32.00 \
    --technique EMBROIDERY --placement embroidery_chest_left --thread-mode detect

# Rehearse without writing to the store
python scripts/attach_printful_design.py --product-id 501345091 --size M \
    --file-url https://example.com/design.png --price 29.99 --dry-run

--dry-run resolves the variant, registers and validates the file, builds the exact PUT payload, prints it, and stops before the write.

Guardrails

  • Never attach a design to a live listing without the owner's approval for that specific listing. The owner's standing rule is that design work is shown for approval before a listing is created or published.
  • Prefer --dry-run first, then apply the same command without it.
  • Keep the token in the environment; never print it or write it into artifacts.