The production-ready Medusa DTC Starter is outRead the announcement
Print2medusa logo

Print2medusa

Printful → Medusa v2 plugin: product sync, auto fulfillment, and admin tools

npm install @legenki/print2medusa
Category
Built by
Service
Version
0.11.4
Last updated
1 week ago
Monthly downloads
Loading downloads

@legenki/print2medusa

npm version npm downloads license

Printful → Medusa v2 plugin: sync Store Products, auto-create Printful orders on payment capture, and a Fulfillment Provider for admin shipping options.

Published on npm as . MIT licensed.

Requirements

  • Node.js 20.19+ or 22.12+, the same as Medusa itself. Node 20 is past end of life; CI runs on 22.
  • Medusa ≥ 2.18.0 (peer dependency , tested against 2.21.1)
  • Printful store on the Manual order / API platform with a private token carrying the , and scopes. is needed only to register the webhook from the admin.

Install

Or add it to a Medusa app the plugin-native way:

npx medusa plugin:add @legenki/print2medusa

Register the plugin and fulfillment provider in :

Then migrate:

npx medusa db:migrate

See for a fuller snippet.

What it does

FeatureHow
Product syncAdmin Sync Now or → runs in the background, one at a time
Multi-currencyPrices in extra currencies at the ECB daily rate ()
Stock awarenessVariants Printful reports as unavailable unpublish the product; restock republishes it
Removal handlingA full sync drafts products that vanished from Printful; a re-add republishes them
Shipping fidelityThe method the customer paid for is confirmed with Printful and sent on the order
Order economicsPrintful's cost and your margin on the Admin order page
Links / (+ metadata IDs)
OrdersOn → creates Printful order with
Fulfillment providerSelect Printful shipping option in Admin locations
Status + product list widget
Admin pagePrintful in the sidebar: sales, sync history, webhook health, stuck-sync recovery
Design parametersPer product: class, technique, where the design goes, base colours with hex
Mockup promptsPaste-ready prompts per product and colour, in three shapes for the three product classes
Merch bundlesOne Medusa product that expands into several Printful items when the order is placed
Shipment trackingPrintful webhooks → Medusa fulfillment + shipment per parcel, with tracking
Order visibilityPrintful status and per-parcel tracking on the Admin order page

Idempotency

  • Re-sync updates existing products via link tables (no duplicates) and upserts variants — price and assortment changes in Printful reach Medusa; manually-added Medusa variants are left untouched.
  • Concurrent / re-fired payment events will not create a second Printful order: the order is claimed insert-first via a unique index on before the Printful API is called.
  • is never retried by the client. A create whose outcome is unknown (timeout, 5xx) is settled by looking the order up by instead. A claim younger than ten minutes is left to the create that owns it, so and arriving together cannot race. Claims still unresolved after that are settled by the job every 15 minutes — an order canceled in Medusa in the meantime is never sent.
  • A parcel whose Medusa fulfillment was created but never marked shipped is completed on the next webhook or retry. Canceling a parcel's fulfillment in Medusa does not cancel the Printful order; only an order-level fulfillment does.
  • A bundle line is fulfilled only when every member has shipped, counted across parcels.
  • Shipping is normalized to the 2-letter Printful expects for US/CA.
  • Printful redelivers webhooks by design. Each event is stored under a derived carrying a unique index, so a redelivery is absorbed rather than producing a second fulfillment. Delivery metadata (, ) is excluded from that id — otherwise the same event would hash differently on each attempt.
  • Events for one order are serialized with a transaction-scoped advisory lock, so two events cannot both pass the "shipment not yet recorded" check and each create a fulfillment for one parcel.

Webhooks

Printful notifies the store of fulfillment progress (, , , ) at:

POST /hooks/printful/<webhookSecret>

Set the secret as a plugin option, then register the endpoint with Printful:

Generate it as hex — — so it is URL-safe as it stands. Other alphabets work too (the registered URL is percent-encoded), but a hex secret is one you can paste into a URL by hand without surprises. The module refuses to start with a secret shorter than 32 characters, but length is all it can check.

must be an origin, optionally with a path prefix, and without a query string, fragment or credentials. is accepted only for , because the secret would otherwise cross the network in cleartext.

The payload is treated as a trigger, not a source of truth: the endpoint stores the event, answers , and the workflow re-reads from Printful for the authoritative state.

An event that cannot be applied yet is kept, not dropped. A webhook can arrive before has linked its order, and an apply can fail on a Printful or database error. Such an event is stored as and the job retries it every 5 minutes, backing off from 5 minutes doubling to 6 hours. After 20 attempts it is marked and shows up in the admin page's webhook health.

The secret is in the URL path

Printful API v1's webhook configuration accepts only , and — there is no custom-header support — so the shared secret has to travel as a path segment. That has consequences worth planning around.

Treat the secret as rotatable, and expect it in access logs. Any reverse proxy, load balancer, or CDN in front of Medusa logs request paths by default, and that is entirely outside this plugin's control. Anyone who can read those logs can forge webhook deliveries.

Mitigations, in rough order of value:

  • Scope it. The secret only authenticates Printful's callback. It grants no API access, and because payloads are re-verified against Printful's API, a forged delivery cannot invent a shipment — at worst it triggers a redundant re-read.
  • Strip it at the proxy. If your proxy supports rewriting logged paths, mask the segment after .
  • Rotate it on any suspected log exposure, and on staff offboarding.

Rotating the secret

  1. Change to a new random value and restart Medusa.
  2. Re-register with Printful so it stops calling the old URL:

Printful keeps one webhook configuration per store, so step 2 replaces the previous URL outright — the old secret stops being accepted as soon as Medusa restarts. Deliveries in flight during the swap are retried by Printful, and duplicate events are absorbed by the stored , so rotation is safe to perform in production.

shows the registered URL with the secret masked, so the admin UI can confirm the configuration without re-exposing the token.

Request logging

Errors raised by this route ( bad token, malformed payload, storage failure) are logged with the secret replaced by , since Medusa's error handler logs the request path verbatim.

One gap remains and cannot be closed from plugin code: errors thrown by Medusa's global body parser — an oversized body or malformed JSON — reach the error handler without running any route-scoped middleware, so those log lines contain the real path. The endpoint's body limit is therefore raised to 1 MB, well above the largest realistic delivery (a 50-line-item measures ~262 KB; the framework default of 100 KB is in fact exceeded by roughly a 25-item order), so genuine Printful traffic does not reach that path. This is another reason to treat the secret as rotatable.

Live shipping rates

Printful quotes shipping for the destination and cart contents instead of you setting a flat price by hand.

These options belong to the provider, not the plugin. Medusa hands a fulfillment provider only the of its own entry, so set on the plugin is never seen: the provider reports that it cannot calculate prices, and every Printful shipping option stays flat.

is not optional. Without it the provider cannot resolve Printful variant ids, and every quote quietly falls back to the flat rate. Medusa resolves an undeclared dependency to rather than failing, so the plugin logs an error at startup instead.

Rates are Medusa amounts, in the currency's main unit — the same unit as every Medusa v2 price: is $5.00, is ¥800. Before 0.10.0 the plugin documented minor units here ( for $5) and returned live quotes the same way, which Medusa charged a hundredfold.

Give an entry for every method you offer. A method with no entry prices at zero rather than blocking checkout: Medusa cannot complete a cart whose shipping price fails to resolve, so an underpriced delivery is the lesser harm. The plugin logs an error each time it happens.

What happens when Printful is unreachable

Checkout still completes. Prices fall back in this order:

  1. A cached quote inside (default 600)
  2. A cached quote past that but within (default 86400)
  3. The flat rate from

A day-old real quote beats a constant someone typed once, which is why the stale tier outranks the flat rate. One Printful call serves every shipping option on a cart — the whole response is cached, and each option is picked from it locally.

Limits worth knowing

  • A method override is sent only when Printful confirmed it live at selection (). Fallback pricing still lets checkout complete; the order then lets Printful pick the method. See the 0.7.0 changelog.
  • Return options are never priced live. Printful quotes outbound shipping only, so a return shipping option must be given a flat admin price.
  • Rates are quoted in the cart's currency by asking Printful to convert. If a quote comes back in another currency it is discarded rather than converted.

Catalog sync

returns right away and the sync runs in the background, so a large catalog no longer holds the request open. The widget polls progress while it runs.

One sync at a time. A second request gets with the running sync's , and the nightly job (, daily at 03:00 server time) skips quietly rather than piling on. This is enforced by a partial unique index in Postgres, not by a check-then-insert, so double-clicking Sync Now cannot start two.

A killed process is recovered lazily. If Medusa dies mid-sync, the log row stays and the widget keeps showing a sync that is no longer alive. Nothing sweeps on a timer: the next sync attempt — manual, or the nightly job — reclaims any claim whose heartbeat is older than (default 60) and proceeds. Products created but not yet linked are deleted on rollback, so a crash leaves no half-imported products behind.

A sync that fails is marked failed at once. If any step throws, the workflow rolls back and the log row is set to with , freeing the claim immediately rather than after .

New products are put on sale where Medusa can sell them. Each created product joins (default: the store's default sales channel) and gets (default: the store's shipping profile). Without a channel the Store API never lists a product; without a profile a cart offers it no shipping option. Both apply on creation only, so channels or profiles you change afterwards are kept. If neither an option nor a store default exists, the sync logs a warning and imports the product anyway.

A product you delete in Medusa is re-imported. Its stale links are dropped on the next sync and the Printful product is created afresh.

Prices in more than one currency

Printful reports a retail price in the store's currency only. A Medusa region in any other currency then has no price for the product, and a storefront shows it at zero. Set to one entry per region currency:

Each sync converts the marked-up store price at the European Central Bank's daily reference rate (free, no key) and writes it beside the original. With the default rounding a converted price goes up to the next .99 and never below the exact conversion. If the rates cannot be fetched, existing variants keep the prices they have — a set missing a currency would leave the product free in that region — and new products get the store currency only until the next sync.

Variants are titled by their options (), and each carries its own mockup in for a storefront to show when that colour is picked.

Stock

A product whose variants Printful all reports as unavailable is set to , and republished when it comes back. The plugin only republishes what it unpublished itself — a product you set to draft by hand stays draft. Variants carry in metadata, and discontinued products get unless .

Sold-out sizes are still orderable in Medusa cart APIs ( is false for POD). Hide or disable them in your storefront by reading — see the storefront availability guide.

Products removed from Printful

After a full sync, linked products that no longer appear in the Printful store list are unpublished by default (). Use to leave publication alone. The plugin never deletes products. Partial syncs with skip this pass.

Order economics

Printful returns what it charged along with the created order, so the plugin stores it on the Medusa order rather than making a second API call. The order page shows the Printful cost, the retail total, and the margin between them. The figures are refreshed whenever a webhook re-reads the order, because Printful finalizes shipping and fees at fulfillment.

Amounts are stored in minor units under , and in order metadata, scaled by the currency's own subunit — $12.34 stores as , ¥1500 stores as . records which rule produced them; orders written before 0.6.0 carry no marker and were scaled by 100 whatever their currency.

Margin is only shown when both figures are in the same currency. If Printful bills in USD while the order is in EUR, both totals are stored and the margin is withheld — converting would need an exchange rate this plugin does not have, and a margin built on a guessed rate is worse than none.

The order page deliberately shows only the two totals and the margin, not the per-fee breakdown. Those three are always written together from one response, so they cannot disagree; the individual fee keys are refreshed per-key and a fee absent from a later response keeps its previous value, so a breakdown need not sum to the total.

The Printful admin page

A Printful section in the sidebar, gathering what the widgets could not:

  • Sales — paid orders and profit from Printful's own reporting
  • Webhooks — when the last event arrived, how many are waiting or failed
  • Recent syncs — status, counters, and live progress while one runs
  • Stuck sync recovery — see below

Two of these behave differently on purpose. Webhook health never calls Printful: a panel whose job is reporting whether Printful reaches you must still render when Printful is down, so it answers from local rows. Sales does call Printful, because the figures do not exist locally — and an outage answers with an empty panel rather than blanking the page.

When a sync gets stuck

If Medusa dies mid-sync, the run stays and nothing else can start until it is reclaimed — up to , one hour by default. The page notices and offers to clear it.

Clearing is deliberately awkward, because it is destructive. The request must carry a typed confirmation, and the server re-checks the heartbeat: if the sync is actually alive, it refuses and tells you so. A wrong guess costs a message, never a killed sync.

A run cleared by a person is recorded as with how long it had been silent, so it is never confused with one the timeout reaped.

Design parameters

Each synced variant carries what the design becomes on that product, read from Printful's public catalog during sync. The admin page shows it per product.

Products fall into three classes, derived from their techniques and placements rather than a hardcoded list — so a product you add later is classified rather than misfiled:

ClassWhat it means for a design
ApparelInk on fabric. Base colour and material drive how the design reads.
EmbroideryThread, not ink. A cap supporting only must never be described as printed.
Print mediaPaper and vinyl. Physical size matters; there is no base colour.

The class matters more than it looks. A dad hat and a t-shirt are both "apparel" in a catalogue sense, but a design on one is stitched and on the other is printed — and its placement is rather than , so anything filtering for front-and-back drops it silently.

Parameters live in variant metadata under , and the panel is built from them without calling Printful.

What it does not show: print area dimensions and DPI. Those need an authenticated endpoint whose response schema Printful does not publish, so the panel says where a design goes rather than how large the printable region is.

Mockup prompts

The Mockup prompts panel turns design parameters into prompts you paste into an image model. Pick a style, say what the artwork is, copy one per product.

The plugin writes prompts and stops there. Generation happens wherever you paste them — which is why no API keys, rate limits or image storage live in this repo. Printful's own mockup generator is a different tool: it renders a product on a plain background, right for a catalogue thumbnail and wrong for an editorial mockup.

Prompts come in three shapes because the products differ in kind:

  • Apparel — a model wearing it, the fabric named, styled with a companion garment chosen by how light the base colour is
  • Embroidery — thread, never ink, and framed head-and-shoulders rather than full-length. The dad hat supports only; a prompt calling it printed would describe something Printful cannot make
  • Print media — an object on a wall. No model, no fabric, no base colour

Colour is the axis the variations run along, and colours are picked for spread across lightness rather than catalogue order — five near-identical heathers would produce five near-identical images.

Nothing is invented. A clause is dropped rather than defaulted when Printful did not report the fact: the cap has no material in the catalog, so its prompt says nothing about fabric.

Merch bundles

A bundle is an ordinary Medusa product — its own page, price and images — whose variant records which member variants it contains:

Printful has no notion of a bundle; it fulfils individual items. So when the order is placed the bundle line is replaced by its members, with each member's quantity multiplied by how many bundles were bought. Two bundles each holding two stickers order four stickers.

Composition is read from the bundle variant when the Printful order is created, never from the order line. Line item metadata is whatever the storefront sent, so a member list there would let a customer choose what Printful prints. An edit to a bundle therefore reaches orders that are paid but not yet sent to Printful. Member quantities must be whole numbers and are capped at 100.

A bundle is stricter about stock than a plain product. A product is drafted only when every variant is gone, since any remaining variant is still sellable. A bundle promises to ship all of it, so one sold-out member takes it off sale — and puts it back when the member returns. Only a full sync reconciles bundles: under a most members go unrefreshed, and stale metadata would draft bundles on last week's stock.

The Bundles panel on the Printful admin page lists each bundle, its members, and which member is unavailable when one is.

Admin usage

  1. Create products in Printful (Store Products).
  2. Open Medusa Admin → Products list → Printful → Sync Now.
  3. Configure a location shipping option using the Printful fulfillment provider.
  4. Place a test order and capture payment → Printful receives the order.

Local plugin development

The integration suite runs against a real Postgres, so it is a separate command rather than part of :

runs both. The integration tests cover what unit tests cannot: that the sync claim is atomic under concurrent inserts, and that a redelivered webhook produces one row rather than two — both of which depend on real unique-index behaviour.

Releasing

Publishing runs from CI on a version tag, so the tarball is always built from a checkout that passed the full suite rather than from a maintainer's laptop:

A tag whose run fails publishes nothing. Fix forward with the next patch version rather than moving the tag, as 0.11.3 did for 0.11.2.

The workflow refuses to publish if the tag and disagree, or if that version is already on npm. It publishes with , so npm records which repository and workflow built the package.

It authenticates with npm trusted publishing, so no npm token is stored in the repository. On npmjs.com the package needs a trusted publisher: Settings → Trusted Publisher → GitHub Actions, organization or user , repository , workflow , no environment. Once a release has gone out that way, set Publishing access to "Require two-factor authentication and disallow tokens" and delete any secret, so a leaked token cannot publish.

In a host Medusa app:

npx medusa plugin:add @legenki/print2medusa

Roadmap

See ROADMAP.md for what each release shipped, what is still unwired, and the path to (stable API and Printful v2 migration).

Architecture notes

  • Printful is source of truth for products; Medusa holds a copy + links.
  • Printful API v1 ().
  • Catalog sync runs as a Medusa workflow in the background: the route claims the run, answers and returns. See Catalog sync.
  • Webhooks carry their secret in the URL path because Printful v1 supports no custom headers — see Webhooks.
  • Multi-store polish and Printful API v2: see ROADMAP.md.

Options

Plugin options go in the entry. The fulfillment provider is configured separately, in its own entry under the fulfillment module, and sees only the options given there.

OptionDescription
Printful private token (required)
for account-level tokens
Per-request deadline for Printful calls in ms (default 15000)
Confirm orders for fulfillment (default true)
Also create Printful order on , once the order is fully captured
Allow orders that mix Printful + non-Printful items
Markup on retail prices during sync
Fallback currency code
Shared secret for the Printful webhook path (see Webhooks)
Minutes before a running sync is presumed dead and reclaimed (default 60)
(default) marks discontinued products, omits the marker
(default) drafts products gone from Printful, leaves them
Extra currencies to price in, e.g. , converted at the ECB daily rate
(default, up to .99), or for converted prices
Sales channels new products join (default: the store's default sales channel)
Shipping profile new products get (default: the store's profile)

Fulfillment provider options:

OptionDescription
Printful private token (required, same as the plugin's)
for account-level tokens
Per-request deadline for Printful calls in ms (default 15000)
Quote shipping from Printful at checkout (see Live rates)
Flat rate per method, in main units, when no live quote is available
How long a quote counts as fresh (default 600)
How long a quote is kept as a fallback (default 86400)

License

MIT © Andy Legenki