Overview
Icon for Allegro Marketplace

Allegro Marketplace

Allegro offers, orders, stock and price sync

Allegro by Koda Plus

Connect an Allegro seller account to Medusa: link every offer to its product variant by signature, see where Allegro and Medusa disagree on stock before buyers do, import Allegro orders into Medusa exactly once, and send quantities, parcels, invoices, prices and draft offers back to Allegro.

Read only until you decide otherwise. Every writer (the order import included) is off until it is allowed in the plugin options AND armed by a person in the admin, and the HTTP client lets through only the exact requests of the writers that are armed.

Live demo: Medusa admin medusa.koda.plus/app/allegro, signed in to a public demo account by the link itself. The demo runs the plugin in demo mode (Copy to clipboarddemo: true): a simulated Allegro account built from the store's catalog, so every screen has data and every writer can be armed without touching Allegro.

What it syncs

  • Seller account (OAuth 2.0 device flow): the seller types a short code at allegro.pl. No redirect URI, no public callback route.
  • Offers (id, name, status, price, quantity, signature): Allegro to Medusa, every hour at minute 45 and on Sync now.
  • Offer to variant links, one primary offer per variant, and the stock check: inside Medusa, on every offer sync.
  • Order journal (status, fulfillment status, lines, total; no buyer data): Allegro to Medusa, every ten minutes.
  • Orders (writer Copy to clipboardorders): Allegro to Medusa, every two minutes from the Allegro order event journal, exactly once per checkout form.
  • Quantities (writer Copy to clipboardstock): Medusa to Allegro, every 15 minutes, plan first.
  • Parcel numbers and seller status (writer Copy to clipboardshipping): Medusa to Allegro, on every fulfillment and shipment and every five minutes.
  • Invoice PDFs (writer Copy to clipboardinvoices): Medusa to Allegro, when the Fakturownia plugin (or any invoicing tool) announces a document, and every five minutes.
  • Prices (writer Copy to clipboardprices): Medusa to Allegro, every hour at minute 52, plan first, inside bounds from metadata.
  • Draft offers by EAN (writer Copy to clipboardpublish): Medusa to Allegro, every hour at minute 57, plan first, drafts only.
  • Customer returns, disputes, claims and unread messages: Allegro to Medusa, read only, at minutes 20 and 50.
  • Live offer links for an "Also on Allegro" button: Medusa to your storefront through Copy to clipboardGET /store/allegro/products/:id.

Features

  • Allegro page in the admin sidebar, not hidden under Settings, with a Panel and a Setup guide view (Copy to clipboard?view=guide opens the guide directly). The panel has counters, the account, the writers, the imported orders, the stock and price plans, the offers, the order journal, the parcels and invoices outbox, customer issues, draft offers and the history. Lists open on deep links (Copy to clipboard?filter=, Copy to clipboard?q=).
  • Cards on the product and the order page: the Allegro offers of a product, and for an imported order what Allegro knows about it (payment, buyer login, delivery and pickup point, totals on both sides, parcels and invoices sent, returns and disputes), with "Mark as handled" and "Retry".
  • Two switches per writer: Copy to clipboardwrites.<writer> in the options (a hard switch: Copy to clipboardfalse cannot be overridden from the admin) and a toggle a person flips in the admin. The admin shows who armed it and when.
  • Plan first: the stock, price and draft writers compute a plan (what would change, from what to what, and why the rest is left alone), the admin shows it, and only an armed writer applies it, with a per run cap and a quarantine for items that keep failing. An incomplete read plans nothing; offers missing from a read are never touched.
  • Circuit breaker: a writer that fails Copy to clipboardbreakerThreshold times in a row (default 5) disarms itself and says why. Failures of one item do not count.
  • Exactly once orders: one row per checkout form before anything happens, an atomic claim with a lease, a lookup of Copy to clipboardmetadata.marketplace_order_ref before every create, repeated inside the lock Copy to clipboardmarketplace-order-ref:<ref> that the BaseLinker plugin takes too. Which orders are the plugin's own is decided by its import table, never by order metadata.
  • Orders that look like any order: created as a draft and placed by Medusa's own Copy to clipboardconvertDraftOrderWorkflow (stock reserved, Copy to clipboardorder.placed emitted), with Allegro prices as tax inclusive lines, tax lines from the region, the delivery method and pickup point, a payment collection marked paid when Allegro holds the money, and no customer account.
  • Stock writer that cannot hurt: decreases by default, ends sold out offers (Allegro cannot hold zero) and never activates an ended offer, re-reads every planned offer right before the command, and refuses a whole plan that looks like a broken read (most variants at zero, or a large share of live offers to end).
  • Parcels and statuses once each, with the carrier from Allegro's own carrier list (or your Copy to clipboardcarriers map), and a seller status that never moves backwards.
  • Invoices once each, from the Fakturownia plugin of Koda Plus (VAT invoices and corrections) or from any tool through an event, with the 3 MB and real PDF checks before anything is sent, in their own outbox and sweep.
  • Customer issues at a glance: open returns, disputes and claims, the ones waiting for your answer, due dates and unread message threads, with links to the right place in the seller panel. The plugin never answers for you.
  • Signature matching: the offer Copy to clipboardexternal.id (the "sygnatura" sellers, feeds and BaseLinker fill with the SKU) against the variant SKU, case insensitive, never by offer name.
  • Production and sandbox: Copy to clipboardenvironment: "sandbox" talks to allegro.pl.allegrosandbox.pl. Tokens of one environment are never used against the other.
  • Demo mode (only with Copy to clipboarddemo: true): a simulated Allegro account built from your catalog runs through the same parsers, planners and workflows as a real one. Evaluate everything without an Allegro developer account.
  • Events for your own alerts: Copy to clipboardallegro.writer.tripped, Copy to clipboardallegro.import.held and Copy to clipboardallegro.outbox.failed.
  • Works with Koda Plus hosts through the shared contract Copy to clipboardkoda.integration/1: one line per imported order, product or variant, board counters and cards a host can embed.
  • References: the stores running the integration, passed in the options, shown under the counters and at the end of the guide.
  • Admin in English and Polish through the Medusa admin translations.
  • Zero dependencies beyond Medusa itself.

Requirements

  • Medusa 2.12 to 2.21 and Node.js 20+ (see Compatibility).
  • For a real account: an app registered at apps.developer.allegro.pl (or the sandbox portal) as an app without access to a browser, which is the device flow.
  • For the order import: a region in PLN and a sales channel linked to the stock location that ships Allegro orders.
  • For the price and draft writers: PLN prices that include tax (a tax inclusive price preference for PLN in Medusa, or Copy to clipboardprices.taxInclusive: true).

Installation

npm install @koda-plus/medusa-plugin-allegro

Yarn and pnpm work the same way: Copy to clipboardyarn add @koda-plus/medusa-plugin-allegro or Copy to clipboardpnpm add @koda-plus/medusa-plugin-allegro.

Configuration

Add the plugin to Copy to clipboardmedusa-config.ts:

module.exports = defineConfig({
// ...
plugins: [
{
resolve: "@koda-plus/medusa-plugin-allegro",
options: {
clientId: process.env.ALLEGRO_CLIENT_ID,
clientSecret: process.env.ALLEGRO_CLIENT_SECRET,
encryptionKey: process.env.ALLEGRO_ENCRYPTION_KEY,
environment: "production", // or "sandbox"
appName: "MyShopAllegro", // the name of your app at Allegro
docsUrl: "https://myshop.example/allegro",
// writes: { orders: true, stock: true, shipping: true, invoices: true },
demo: process.env.ALLEGRO_DEMO === "true", // a simulated account, only when switched on
},
},
],
})

Set the credentials in Copy to clipboard.env. Generate the encryption key with Copy to clipboardopenssl rand -base64 32:

ALLEGRO_CLIENT_ID=your-client-id
ALLEGRO_CLIENT_SECRET=your-client-secret
ALLEGRO_ENCRYPTION_KEY=base64-encoded-32-bytes

Run the migrations, then open Allegro in the admin sidebar:

npx medusa db:migrate

Missing options never break the boot: the module registers, the admin lists what is missing and the scheduled jobs wait. Missing keys never switch on demo mode: it runs only when Copy to clipboarddemo is Copy to clipboardtrue, so a production store without keys simply waits for its configuration.

Options

Connection:

  • Copy to clipboardclientId, Copy to clipboardclientSecret: the Allegro app credentials.
  • Copy to clipboardencryptionKey: 32 random bytes in base64. Encrypts the tokens and the device code at rest with AES-256-GCM. A wrong key never deletes the stored tokens: the account reads as not connected and the status says why, until the right key is back.
  • Copy to clipboardpreviousEncryptionKeys (default Copy to clipboard[]): keys used before Copy to clipboardencryptionKey, for a key rotation. Stored tokens are read with them and saved again under the current key on the next use; remove them once the account has refreshed its token.
  • Copy to clipboardenvironment (default Copy to clipboardproduction): Copy to clipboardproduction or Copy to clipboardsandbox.
  • Copy to clipboarddemo (default Copy to clipboardfalse): the simulated account, only when this is Copy to clipboardtrue (Copy to clipboarddemo: process.env.ALLEGRO_DEMO === "true" in the configuration above). Nothing is sent to Allegro. Do not switch it on in a production store: with the order import armed, demo orders are created in that store (see Demo mode).
  • Copy to clipboardappName (default none): the name of your app at Allegro. Allegro asks for Copy to clipboardAppName/Version (+DocsUrl) as the User-Agent with the name of the registered app.
  • Copy to clipboarddocsUrl (default Copy to clipboardhttps://koda.plus): the https address in the User-Agent.
  • Copy to clipboarduserAgent (default built from Copy to clipboardappName and Copy to clipboarddocsUrl): the whole User-Agent, when you need to set it yourself.
  • Copy to clipboardrequestsPerMinute (default Copy to clipboard300): a self-imposed limit. Allegro allows 9 000 requests per minute per client id and blocks the client id for a minute above it.
  • Copy to clipboardtimeoutMs (default Copy to clipboard20000): the timeout of one request.

Reading:

  • Copy to clipboardsyncEnabled (default Copy to clipboardtrue): the hourly offer sync.
  • Copy to clipboardordersEnabled (default Copy to clipboardtrue): the order journal.
  • Copy to clipboardstockLocationIds (default: all locations): the stock locations whose quantities count in the stock check and the stock writer.

Writers (each one also needs a person to arm it in the admin):

  • Copy to clipboardwrites.orders, Copy to clipboardwrites.stock, Copy to clipboardwrites.shipping, Copy to clipboardwrites.invoices, Copy to clipboardwrites.prices, Copy to clipboardwrites.publish (default Copy to clipboardfalse each; in demo mode a writer you do not mention is allowed, except Copy to clipboardwrites.orders, which creates orders in your store and needs Copy to clipboardtrue in demo mode too; an explicit Copy to clipboardfalse always wins). The consent asks Allegro only for the scopes of the writers allowed here: Copy to clipboardallegro:api:sale:offers:write for stock, prices and drafts, Copy to clipboardallegro:api:orders:write for parcels and invoices. After changing Copy to clipboardwrites, connect the account again; the admin says which scopes are missing.
  • Copy to clipboardbreakerThreshold (default Copy to clipboard5): consecutive failures after which a writer disarms itself.

Stock writer:

  • Copy to clipboardstockPush (default Copy to clipboard"decrease"): Copy to clipboard"decrease" only lowers Allegro quantities to what Medusa has; Copy to clipboard"mirror" also raises them, and only while the order import is armed, has run successfully in the last 15 minutes and holds nothing.
  • Copy to clipboardstockPushCap (default Copy to clipboard50): offers one run may change.
  • Copy to clipboardendOffersAtZero (default Copy to clipboardtrue): end the offer of a variant that sold out in Medusa (Allegro cannot set a quantity to zero). Copy to clipboardfalse only reports it.

Order import:

  • Copy to clipboardorderImport.salesChannelId (default: a sales channel named "Allegro", otherwise the store default with a warning; in demo mode an "Allegro (demo)" channel is created and linked to the default channel's stock locations, so the stock check sees your stock; nothing is reserved for demo orders).
  • Copy to clipboardorderImport.regionId (default: the first region in PLN).
  • Copy to clipboardorderImport.shippingOptionId (default none): a shipping option put on every imported order, so it can be fulfilled without picking one.
  • Copy to clipboardorderImport.shippingOptions (default Copy to clipboard{}): per Allegro delivery method id or name, the Medusa shipping option to use. The method data of an order on a mapped option is validated by that option's provider before the order is created, as a cart does: with the InPost plugin of Koda Plus the order carries its InPost option and parcel locker (Copy to clipboardmachine_id), and a fulfillment becomes a parcel sent with your own ShipX contract (standard services, not Wysyłam z Allegro). It is handed over only when the payment type is known, a pickup delivery keeps its point, cash on delivery agrees with the payment type and collects exactly the Allegro total; otherwise the order keeps the Copy to clipboardallegro_* keys and its import row asks a person. Orders on the default Copy to clipboardshippingOptionId and demo orders are never handed over: the default lands every carrier, and an ORLEN or DPD point must not become an InPost parcel. When the created order's total differs from Allegro on a cash on delivery hand-over, the row asks a person to correct the amount before shipping. If you send Allegro parcels elsewhere (Wysyłam z Allegro, BaseLinker) and still map methods to InPost options, add Copy to clipboardallegro_checkout_form_id to the InPost plugin's Copy to clipboardskipMetadataKeys, or map them to an option of another provider: a Medusa fulfillment of a handed order is a ShipX parcel.
  • Copy to clipboardorderImport.perRun (default Copy to clipboard25): orders one run creates at most.

Parcels:

  • Copy to clipboardcarriers (default Copy to clipboard{}): Medusa fulfillment provider id (or its prefix) to an Allegro carrier id, for example Copy to clipboard{ "manual_manual": "OTHER", "inpost": "INPOST" }. Without a match the carrier is looked up in Allegro's carrier list by name, then sent as Copy to clipboardOTHER with the provider name.

Invoices:

  • Copy to clipboardinvoiceKinds (default Copy to clipboard["vat", "correction"]): the Fakturownia document kinds attached to Allegro orders (Copy to clipboardvat, Copy to clipboardcorrection, Copy to clipboardreceipt, Copy to clipboardproforma).

Prices:

  • Copy to clipboardprices.priceListId (default: the variant's default price): read the Medusa price from this price list.
  • Copy to clipboardprices.minKey (default Copy to clipboardallegro_price_min) and Copy to clipboardprices.maxKey (default Copy to clipboardallegro_price_max): variant (or product) metadata keys with the lowest and highest allowed Allegro price.
  • Copy to clipboardprices.requireFloor (default Copy to clipboardtrue): never change a price without a floor.
  • Copy to clipboardprices.maxChangePercent (default Copy to clipboard30): a bigger change is refused, never clamped.
  • Copy to clipboardprices.cap (default Copy to clipboard20): offers one run may change.
  • Copy to clipboardprices.taxInclusive (default: read from Medusa): Allegro takes gross prices. Unset, the plugin reads the PLN price preference of Medusa, and while it says the prices exclude tax (Medusa's default) the price and draft plans are refused with Copy to clipboardtax_exclusive_prices and nothing is sent. Copy to clipboardtrue: your PLN prices include tax. Copy to clipboardfalse: they do not, and the plans stay refused.

Draft offers by EAN:

  • Copy to clipboardpublish.shippingRatesId (required to publish): the id or name of a shipping rates set from the seller panel.
  • Copy to clipboardpublish.location (required to publish): Copy to clipboard{ city, postCode, province, countryCode }; for Poland Copy to clipboardprovince is required (for example Copy to clipboardMAZOWIECKIE) and Copy to clipboardpostCode is Copy to clipboardXX-XXX.
  • Copy to clipboardpublish.invoice (default Copy to clipboard"VAT"): Copy to clipboardVAT, Copy to clipboardVAT_MARGIN, Copy to clipboardWITHOUT_VAT or Copy to clipboardNO_INVOICE.
  • Copy to clipboardpublish.cap (default Copy to clipboard5): drafts one run may create.

Customer issues:

  • Copy to clipboardissues.returns (default Copy to clipboardtrue): customer returns, with the orders scope.
  • Copy to clipboardissues.disputes (default Copy to clipboardfalse, Copy to clipboardtrue in demo mode): disputes and claims. Needs Copy to clipboardallegro:api:disputes, which has no read-only variant.
  • Copy to clipboardissues.messages (default Copy to clipboardfalse, Copy to clipboardtrue in demo mode): unread message threads. Needs Copy to clipboardallegro:api:messaging, which has no read-only variant.

References:

Setup in brief

The admin has the full guide (Allegro, then Setup guide), with each step ticked from the live state of your store.

  1. Register an app at apps.developer.allegro.pl as an app without access to a browser, name it without spaces and copy the client id and secret.
  2. Optionally do it all first in the sandbox (apps.developer.allegro.pl.allegrosandbox.pl, Copy to clipboardenvironment: "sandbox").
  3. Generate the encryption key (Copy to clipboardopenssl rand -base64 32) and keep it in the environment.
  4. Add the plugin with Copy to clipboardclientId, Copy to clipboardclientSecret, Copy to clipboardencryptionKey, Copy to clipboardappName and Copy to clipboarddocsUrl, run Copy to clipboardnpx medusa db:migrate and restart.
  5. Click Connect Allegro account; the seller types the code at allegro.pl/skojarz-aplikacje.
  6. Run the first offer sync and check that History shows it as OK.
  7. Review the offers without a product and without a signature; fix signatures or SKUs.
  8. Read the stock check and run a dry run of the stock plan.
  9. Allow only the writers you will use in Copy to clipboardwrites, then Connect again so the seller grants the wider scopes.
  10. Arm the order import first, after a dry run in Imported orders; bring older orders in with the catch-up import.
  11. Arm the stock writer and watch its plan for a day.
  12. Arm parcels and status; set Copy to clipboardorderImport.shippingOptionId or Copy to clipboardcarriers when needed.
  13. Arm invoices (with the Fakturownia plugin or your own event).
  14. Turn on customer issues if you want disputes and messages counted.
  15. Optionally arm prices, after putting floors in metadata.
  16. Optionally plan drafts by EAN, after setting Copy to clipboardpublish.shippingRatesId and Copy to clipboardpublish.location.

Arm one writer at a time, each after its dry run, and go live when the checklist at the end of the guide is all ticked.

How the order import works

  1. The import reads the Allegro order event journal (Copy to clipboardGET /order/events) from its cursor and writes one row per checkout form in Copy to clipboardallegro_order_import. Event ids are opaque: they are never compared, the events are taken in the order Allegro returns them, and the cursor moves to the last event of a page only after the page's rows are written. A fresh install starts at the newest event, so history comes in only through the catch-up import (orders bought between two dates, up to 62 days at once, queued once each). Allegro keeps events for 60 days; a longer pause restarts at the newest event and says so.
  2. Every due row is claimed atomically and looked up in Medusa by Copy to clipboardmetadata.marketplace_order_ref = "allegro:<checkout form id>". An order counts as the plugin's own only when its import row names it (or it is still a draft no cart placed): such an order from an earlier attempt is adopted and finished, never created again. An order another integration imported (the BaseLinker plugin of Koda Plus writes the same key) makes this plugin step back and say so; a shopper's cart metadata can never make an order look like an Allegro one.
  3. The checkout form is read fresh and mapped: every line by its offer link first, then by its signature. A line that matches no variant holds the whole order with the reason; no product is ever invented. So do a missing address, a currency the region does not use and stock Medusa cannot cover.
  4. Holding the lock Copy to clipboardmarketplace-order-ref:allegro:<checkout form id> in the Medusa Locking module, the reference is looked up again and the order is created as a draft with Copy to clipboardcreateOrderWorkflow; its id is written on the row at once. The buyer e-mail goes on the draft (no customer is created), tax lines are computed where the region left none, and the draft is placed with Copy to clipboardconvertDraftOrderWorkflow, which reserves the stock and emits Copy to clipboardorder.placed. A payment collection for the total follows, marked paid (captured) when Allegro holds the money and left not paid for cash on delivery. Demo orders skip the placing and the payment (see Demo mode).
  5. A cancellation on Allegro cancels the Medusa order only when nothing was fulfilled; otherwise the row asks a person to handle the return. Medusa's Copy to clipboardcancelOrderWorkflow refunds a captured payment and emits Copy to clipboardorder.canceled, so plugins that react to refunds (an invoice correction, for example) see it.
  6. When the buyer changes the delivery address, the pickup point or the invoice data on Allegro after the import, the row asks a person to compare (the Medusa order is never changed by itself). Mark as handled on the order card or in Imported orders clears it.
  7. A held import emits Copy to clipboardallegro.import.held; a person retries it with Retry. When Allegro or the network is away for a moment (no answer, 5xx, 429), the next run tries again and the circuit breaker does not count it, so an outage never disarms the import.

Copy to clipboardorder.placed is emitted on purpose, like the BaseLinker plugin does: invoicing (the Fakturownia plugin issues the invoice the invoices writer then attaches), the ERP (the Subiekt nexo plugin creates its document) and your own stock follow-ups see Allegro orders like any other. Imported orders carry Copy to clipboardno_notification: true and Copy to clipboardmetadata.marketplace_order_ref. Allegro writes to its buyer itself, so make the subscriber that sends your order confirmation skip them:

// src/subscribers/order-placed.ts in your store
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
import { Modules } from "@medusajs/framework/utils"
export default async function orderPlaced({ event, container }: SubscriberArgs<{ id: string }>) {
const order = await container.resolve(Modules.ORDER).retrieveOrder(event.data.id, { select: ["id", "metadata", "no_notification"] })
/* Allegro and BaseLinker orders: the marketplace already wrote to the buyer. */
if (order.metadata?.marketplace_order_ref || order.no_notification) return
// ...send your confirmation e-mail
}
export const config: SubscriberConfig = { event: "order.placed" }

What each imported order carries in its metadata: Copy to clipboardmarketplace_order_ref, Copy to clipboardallegro_checkout_form_id, Copy to clipboardallegro_marketplace, Copy to clipboardallegro_payment_type, Copy to clipboardallegro_buyer_login, Copy to clipboardallegro_delivery_method, Copy to clipboardallegro_pickup_point_id, Copy to clipboardallegro_invoice_required and Copy to clipboardnip when the buyer asked for an invoice; demo orders also Copy to clipboardallegro_demo and Copy to clipboardkoda_demo. These keys are for people and other tools; the plugin itself decides from its import table. Every line keeps Copy to clipboardallegro_line_item_id, Copy to clipboardallegro_offer_id and Copy to clipboardallegro_offer_name.

The other writers

  • Stock: for every primary offer linked to a variant, the Allegro quantity against what Medusa has available (stocked minus reserved in the chosen locations; a kit counts its scarcest part). The plan says decrease, end, increase (mirror only) or why nothing happens, and the run sends one Copy to clipboardoffer-quantity-change-command per target value (or an Copy to clipboardEND publication command) for at most Copy to clipboardstockPushCap offers, after reading every planned offer again.
  • Parcels and status: when an imported order gets a fulfillment with tracking numbers in Medusa, each number goes to the Allegro order once (Copy to clipboardPOST /order/checkout-forms/{id}/shipments), the seller status becomes Copy to clipboardREADY_FOR_SHIPMENT, and Copy to clipboardSENT when everything shipped. Every send is looked up on Allegro first; an unclear answer is checked on Allegro before anything is sent again.
  • Invoices: the Fakturownia plugin of Koda Plus announces Copy to clipboardfakturownia.document.issued and Copy to clipboardfakturownia.document.corrected with Copy to clipboard{ id, order_id, kind, number, external_id, demo }; the PDF is read through the Fakturownia module (resolved at run time, never imported) and uploaded once with Copy to clipboardPOST /order/{orderId}/billing-documents/files, after looking at the invoices already on the order. Any other tool can emit Copy to clipboardallegro.invoice.attach.requested with Copy to clipboard{ order_id, filename, url, number } (an https address).
  • Prices: the Medusa price (or a price list) against the price of every live linked offer, inside the floor and ceiling from metadata; a price outside them, or a change bigger than Copy to clipboardprices.maxChangePercent, is refused and never clamped. Only gross prices go out (see Copy to clipboardprices.taxInclusive). Right before the command the offer is read again, and the price goes only while Allegro still shows the price the plan started from: a price somebody changed in the seller panel waits for the next plan.
  • Draft offers: variants with a valid EAN and no offer are matched to exactly one Allegro catalog product (several matches are never guessed) and created as Copy to clipboardINACTIVE drafts with the SKU as signature, at the gross Medusa price. You review and activate them on Allegro.
  • Parcels and invoices of orders fulfilled or invoiced before Copy to clipboardwrites.shipping or Copy to clipboardwrites.invoices was allowed are not sent later: those writers start from the events they see.

Demo mode

Copy to clipboarddemo: true, and only that, runs a simulated Allegro account built from your catalog through the same parsers, planners and workflows as a real account, with every row flagged Copy to clipboarddemo:

  • offers for your variants, with a few deliberate mismatches (an offer without a product, one without a signature, an ended offer still in stock);
  • three to five checkout forms a day at fixed times, deterministic, with buyers at Copy to clipboard@example.com only: online payments, cash on delivery, a company invoice with a NIP, parcel lockers, a cancellation every other day and, every third day, an order whose line has no product;
  • armed writers change the simulation: quantities, ended offers, prices, drafts, parcels (a simulated courier ships imported demo orders two hours after import) and invoices (the Fakturownia demo PDF when that plugin is present, a simulated one page PDF otherwise);
  • customer returns, disputes, a claim and unread threads.

The sample data is built by the job Copy to clipboardallegro-demo-seed (every minute, demo mode only, until every kind exists) or at once with Prepare now on the page (Copy to clipboardPOST /admin/allegro/demo/seed). Opening the page never builds anything.

The order import is the one writer that touches your store, so in demo mode too it needs Copy to clipboardwrites: { orders: true }, and the arming dialog says so. A demo order is created in this Medusa store, in the "Allegro (demo)" sales channel, with Copy to clipboardmetadata.koda_demo: true, and moved from draft to Copy to clipboardpending in the order module itself: it is never placed or paid, so no stock is reserved, no Copy to clipboardorder.placed or Copy to clipboardpayment.captured reaches invoicing, the ERP or e-mails, and a cancellation on the simulated account cancels it quietly (no Copy to clipboardorder.canceled, no refund). Other plugins can skip such orders by Copy to clipboardmetadata.koda_demo; the proof is Copy to clipboardallegro_order_import.demo.

Nothing is ever sent to Allegro in demo mode.

Events

The plugin emits Medusa events with ids, codes and the mode, never buyer data, so you can wire a Discord ping or an e-mail without polling the admin:

  • Copy to clipboardallegro.writer.tripped Copy to clipboard{ writer, failures, message, demo }: the circuit breaker disarmed a writer.
  • Copy to clipboardallegro.import.held Copy to clipboard{ import_id, checkout_form_id, reason_code, demo }: an Allegro order is waiting for a person.
  • Copy to clipboardallegro.outbox.failed Copy to clipboard{ outbox_id, writer, checkout_form_id, order_id, demo }: a parcel, status or invoice could not be sent.
// src/subscribers/allegro-alerts.ts in your store
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
export default async function allegroAlerts({ event }: SubscriberArgs<Record<string, unknown>>) {
if (event.data.demo) return
// post event.name and event.data to your channel
}
export const config: SubscriberConfig = { event: ["allegro.writer.tripped", "allegro.import.held", "allegro.outbox.failed"] }

API routes

All admin routes need an admin session or token.

  • Copy to clipboardGET /admin/allegro: status, counters, writers, plans, imports, outbox, issues, the last runs and, in demo mode, Copy to clipboarddemoSeed (the sample data not built yet). Reads only.
  • Copy to clipboardPOST /admin/allegro/demo/seed: demo mode, build the missing sample data now (202).
  • Copy to clipboardPOST /admin/allegro/connect and Copy to clipboardPOST /admin/allegro/connect/poll: the device login. Copy to clipboardPOST /admin/allegro/disconnect: forget the tokens.
  • Copy to clipboardPOST /admin/allegro/sync with Copy to clipboard{ "what": "offers" | "orders" | "all" }: a sync in the background (202).
  • Copy to clipboardGET /admin/allegro/offers: the snapshot, with Copy to clipboardfilter (all, linked, unmatched, stock, ended_in_stock, ended, drafts, nokey), Copy to clipboardq, Copy to clipboardlimit, Copy to clipboardoffset.
  • Copy to clipboardGET /admin/allegro/orders: the journal, with Copy to clipboardfilter (all, open, sent, cancelled, unmatched, imported, held), Copy to clipboardq, Copy to clipboardlimit, Copy to clipboardoffset; every row carries its import and Medusa order.
  • Copy to clipboardPOST /admin/allegro/writers/:key with Copy to clipboard{ "armed": true | false }: arm or disarm Copy to clipboardorders, Copy to clipboardstock, Copy to clipboardshipping, Copy to clipboardinvoices, Copy to clipboardprices or Copy to clipboardpublish (409 with the reason when it cannot be armed).
  • Copy to clipboardGET /admin/allegro/plans?kind=stock|prices|publish: a plan, with Copy to clipboardfilter, Copy to clipboardq, Copy to clipboardlimit, Copy to clipboardoffset. Copy to clipboardPOST /admin/allegro/plans with Copy to clipboard{ kind, mode: "plan" | "apply" }: a dry run now, or plan and apply in the background (409 when the writer is not armed). Copy to clipboardPOST /admin/allegro/plans/:id/release: take an item out of quarantine.
  • Copy to clipboardGET /admin/allegro/imports: the imported orders, with Copy to clipboardfilter (all, imported, held, pending, attention, skipped, cancelled), Copy to clipboardq, Copy to clipboardlimit, Copy to clipboardoffset. Copy to clipboardPOST /admin/allegro/imports with Copy to clipboard{ mode: "plan" | "apply" }: a preview of the next run, or a run now (409 when the writer is not armed). Copy to clipboardPOST /admin/allegro/imports/window with Copy to clipboard{ from, to }: the catch-up import, queue the forms bought between two dates. Copy to clipboardPOST /admin/allegro/imports/:id/retry: retry a held or skipped form. Copy to clipboardPOST /admin/allegro/imports/:id/handled: a person checked an order that needed attention.
  • Copy to clipboardGET /admin/allegro/medusa-orders/:id: what Allegro knows about one Medusa order (its import, parcels and invoices sent, returns and disputes), for the order card; Copy to clipboardimport: null for an order the plugin did not import.
  • Copy to clipboardGET /admin/allegro/outbox?writer=shipping|invoices&status=: parcels, statuses and invoices. Copy to clipboardPOST /admin/allegro/outbox with Copy to clipboard{ writer }: send what is due now. Copy to clipboardPOST /admin/allegro/outbox/:id/retry: retry a failed row.
  • Copy to clipboardGET /admin/allegro/issues: returns, disputes and claims, with Copy to clipboardfilter (open, needs_reply, returns, disputes, claims, all). Copy to clipboardPOST /admin/allegro/issues: refresh now.
  • Copy to clipboardGET /admin/allegro/runs: the history, optionally Copy to clipboardkind (offers, orders, stock, prices, import, shipping, invoices, issues, publish).
  • Copy to clipboardGET /admin/allegro/products/:id: offers linked to a product.
  • Copy to clipboardGET /store/allegro/products/:id: live offers of a product for the storefront.
  • Copy to clipboardGET /admin/allegro/integration, Copy to clipboardGET /admin/allegro/integration/summary, Copy to clipboardGET /admin/allegro/integration/attention: the Copy to clipboardkoda.integration/1 contract (see below).

Writes need a JSON body (Copy to clipboardContent-Type: application/json) or the Copy to clipboardx-koda-request header. A server error answers a plain message; the details go to the server log, masked. No route uses DELETE.

Works with Koda Plus hosts

An app that shows every Koda Plus plugin in one place (like medusa.koda.plus) reads Allegro through the shared contract Copy to clipboardkoda.integration/1 and never needs to know its tables:

  • Copy to clipboardGET /admin/allegro/integration: the manifest (mode, configuration, writers armed, widgets, problems).
  • Copy to clipboardGET /admin/allegro/integration/summary?entity=order&id=order_... (or Copy to clipboardids=, up to 50; also Copy to clipboardentity=product and Copy to clipboardentity=variant): one line per record. An order has a line only when the plugin imported it, by its import row, never by order metadata: a changed or cancelled order after the import or a total that differs is red, a held import orange, an import under way blue, an imported order green. Its facts: Copy to clipboardchannel (Copy to clipboardAllegro, code Copy to clipboardallegro, the buyer login, priority 80), Copy to clipboardpayment (code Copy to clipboardcod for cash on delivery or Copy to clipboardpaid when paid on Allegro, priority 70), Copy to clipboarddelivery (the Allegro delivery method and pickup point, priority 60; InPost's own parcel fact at 80 wins in a host) and Copy to clipboardbuyer (the login, priority 60). A product or variant speaks through its linked offers: a stock problem (Allegro sells more than Medusa has, or a sold out variant still live) is orange, a live offer green, drafts and ended offers grey, with a Copy to clipboardlisting fact that links the offer on allegro.pl (the sandbox host in sandbox mode, the plugin page for demo offers).
  • Copy to clipboardGET /admin/allegro/integration/attention?scope=orders,products: counters Copy to clipboardimports_attention (red), Copy to clipboardimports_held, Copy to clipboardissues_open and Copy to clipboardoffers_stock_problem (orange), each with a link to its list (Copy to clipboard/allegro?filter=attention, Copy to clipboard/allegro?filter=held, Copy to clipboard/allegro?filter=issues, Copy to clipboard/allegro?filter=stock).
  • The cards register as Copy to clipboardallegro.order for the zone Copy to clipboardorder.details (hidden for orders without a line) and Copy to clipboardallegro.product for the zone Copy to clipboardproduct.details; a host that claims the zone shows them as a tab (Copy to clipboardembedded) and Medusa's own spot stays empty. Without a host nothing changes.
  • The page opens on deep links: Copy to clipboard?filter= (offers: Copy to clipboardall, Copy to clipboardlinked, Copy to clipboardunmatched, Copy to clipboardstock, Copy to clipboardended_in_stock, Copy to clipboardended, Copy to clipboarddrafts, Copy to clipboardnokey; imports: Copy to clipboardheld, Copy to clipboardattention, Copy to clipboardpending, Copy to clipboardimported, Copy to clipboardskipped, Copy to clipboardcancelled; orders: Copy to clipboardopen, Copy to clipboardsent; issues: Copy to clipboardissues, Copy to clipboardneeds_reply, Copy to clipboardreturns, Copy to clipboarddisputes, Copy to clipboardclaims), Copy to clipboard?q= (a search in that list) and Copy to clipboard?list=offers|orders|imports|issues when a filter alone is ambiguous, for example Copy to clipboard/allegro?filter=attention&q=<checkout form id>.

Public API

What other code may import: Copy to clipboard@koda-plus/medusa-plugin-allegro/workflows (the workflows and the functions below), Copy to clipboard@koda-plus/medusa-plugin-allegro/modules/allegro (the module and its options) and Copy to clipboard/admin. Type declarations ship with the package. Every other path is internal and may change in any release.

Workflows and functions

From Copy to clipboard@koda-plus/medusa-plugin-allegro/workflows: Copy to clipboardsyncAllegroOffersWorkflow, Copy to clipboardsyncAllegroOrdersWorkflow, Copy to clipboardimportAllegroOrdersWorkflow, Copy to clipboardpushAllegroStockWorkflow, Copy to clipboardpushAllegroPricesWorkflow, Copy to clipboardpushAllegroShipmentsWorkflow, Copy to clipboardattachAllegroInvoicesWorkflow, Copy to clipboardsyncAllegroIssuesWorkflow, Copy to clipboardpublishAllegroOffersWorkflow, and the functions behind them (Copy to clipboardrunOrderImport, Copy to clipboardqueueCatchUpImport, Copy to clipboardretryImport, Copy to clipboardmarkImportHandled, Copy to clipboardrunStockPush, Copy to clipboardrunPricePush, Copy to clipboardrunShipping, Copy to clipboardrunInvoices, Copy to clipboardrunIssues, Copy to clipboardrunPublish, Copy to clipboardseedDemo, Copy to clipboardcreateAllegroDraft, Copy to clipboardcompleteAllegroOrder), plus Copy to clipboardallegroIntegration (the contract routes as functions).

import { pushAllegroStockWorkflow } from "@koda-plus/medusa-plugin-allegro/workflows"
/* A dry run: the plan, nothing sent. */
const { result } = await pushAllegroStockWorkflow(container).run({
input: { trigger: "manual", mode: "plan" },
})

Security

  • Write allowlist: every request to the Allegro REST API goes through a check that lets GET and HEAD through and, for anything else, only the exact method and path of a writer that is armed right now: Copy to clipboardPUT /sale/offer-quantity-change-commands/{uuid} and Copy to clipboardPUT /sale/offer-publication-commands/{uuid} with Copy to clipboardEND only (stock), Copy to clipboardPUT /sale/offer-price-change-commands/{uuid} (prices), Copy to clipboardPOST /order/checkout-forms/{uuid}/shipments and Copy to clipboardPUT /order/checkout-forms/{uuid}/fulfillment (parcels), Copy to clipboardPOST /order/{uuid}/billing-documents/files (invoices), Copy to clipboardPOST /sale/product-offers with an Copy to clipboardINACTIVE publication only (drafts). The bodies are checked too: a quantity must be a positive whole number, an offer is never activated. The only other POSTs go to the OAuth server.
  • Narrow scopes: read scopes, plus the write scopes of the writers allowed in Copy to clipboardwrites, plus disputes and messaging only when switched on.
  • Encrypted tokens: AES-256-GCM with a random IV per write; the key lives in your environment, not in the database. A configuration mistake never costs the seller a new consent: a wrong key or a wrong client secret leaves the tokens in place, and only Allegro's Copy to clipboardinvalid_grant (the consent itself is gone) disconnects the account. Copy to clipboardpreviousEncryptionKeys rotates the key.
  • Admin writes from the admin only: every write to Copy to clipboard/admin/allegro* needs a JSON body or the Copy to clipboardx-koda-request header, which a form on another site cannot send, so a cross-site request cannot arm a writer or disconnect the account.
  • Reserved metadata: the store routes (carts, line items, the customer) refuse Copy to clipboardallegro_*, Copy to clipboardmarketplace_order_ref and Copy to clipboardkoda_demo in shopper metadata (400 Copy to clipboardreserved_metadata_key). The plugin never trusts those keys anyway: its own tables are the record.
  • One refresh across processes: a lease in the database serializes token refreshes between a server and a worker, because each refresh hands out a new refresh token and the previous one stops working about a minute later.
  • Leases and locks: one stock, price or draft run at a time across processes; one importer per marketplace order through the shared lock.
  • Secrets stay on the server: the client secret, the keys and the tokens never reach the admin or an answer. They and any long token-like string are masked in logs, stored errors and the admin; a server error answers a plain message without the exception text.
  • Rate limited, with retries only for transient errors: network, 5xx and 429. A write that got no clear answer is never repeated blindly: it is looked up on Allegro first.

Personal data

The plugin's own tables store ids, statuses, amounts, dates, reason codes and reasons, never a buyer's name, address, e-mail or phone, and never the text of a dispute or message. The import row of an order keeps the buyer's Allegro login, the delivery method and the pickup point (for the order card) and a short hash of the delivery and invoice data (to notice a change after the import), not the data itself. The order import needs the buyer's data to ship the order, so it puts it where any store order keeps it: in the Medusa order (the delivery and invoice addresses, the phone, Allegro's masked buyer e-mail, the buyer login and the NIP when an invoice was asked for). No customer account is created. In demo mode every buyer is fictional, at Copy to clipboard@example.com.

Out of scope

  • Writing offers from scratch (descriptions, photos, parameters): drafts by EAN reuse a product from the Allegro catalog, and a person activates them on Allegro.
  • Offer content, renewals and reactivation of ended offers; promotions, price automation rules on Allegro, fees and campaigns.
  • Talking to buyers: messages, disputes, claims, accepting returns and refunds stay in the seller panel, which the plugin links to.
  • Instant stock pushes: the stock writer runs on its 15 minute schedule.
  • Labels and courier orders (Allegro Delivery, Wysyłam z Allegro): the plugin sends the tracking numbers your fulfillment already has.
  • Issuing invoices: the Fakturownia plugin or your own tool does it, the plugin attaches the PDF.
  • More than one seller account per store, or an Allegro marketplace other than allegro.pl for the import.
  • A run against a real Allegro account: the writers are tested against fakes and in demo mode on Medusa 2.15.3, and every call follows the official documentation (Copy to clipboarddocs/allegro-api-notes.md). Start in the sandbox.

Uninstall

  1. Disarm every writer in Settings, then Disconnect the account. The consent stays on the Allegro side until the seller removes it in the account settings (Allegro, Moje Allegro, connected apps).
  2. Remove the plugin from Copy to clipboardmedusa-config.ts and the package from Copy to clipboardpackage.json.
  3. The tables Copy to clipboardallegro_* stay with your data; drop them by hand when you no longer need the history. Imported orders stay in Medusa with their Copy to clipboardallegro_* metadata, as any order would.
  4. After a demo: the demo orders (Copy to clipboardmetadata.koda_demo, channel "Allegro (demo)") reserved nothing; cancel or archive them, then delete the "Allegro (demo)" sales channel.

Compatibility

Medusa 2.12 to 2.21 (peer range Copy to clipboard^2.12.0) and Node.js 20+. The release of each version runs the smoke test on a fresh Medusa 2.12.6 and 2.21.2 app: migrations, build, start and the admin pages. Developing the plugin needs Node.js 22.6+ (the tests run the TypeScript sources directly).

Development

npm install
npm test
npm run typecheck
npm run build

Copy to clipboardnpm test covers the parsers, the matching, the stock check and both planners, the event journal with opaque ids (pages, restarts, repeats), the order import state machine (exactly once, the shared lock, drafts finished after a crash, ownership by the import row), demo orders that are never placed or paid, the outbox, carriers, invoices, issues, drafts, gross prices only, the write allowlist, the writers, the circuit breaker and its event, tokens kept on key and secret mistakes, the route guards, the store SQL, the encryption, the demo simulation and the Copy to clipboardkoda.integration/1 contract. To try the plugin in a Medusa app, run Copy to clipboardnpx medusa plugin:publish here, then Copy to clipboardnpx medusa plugin:add @koda-plus/medusa-plugin-allegro in the app.

Commercial support

Built and maintained by Koda Plus, a Medusa agency from Poland. The device login, the offer read and the matching come from the Allegro integration we maintain for a tyre and wheel retailer with about 4 000 live offers, next to our OLX, BaseLinker, Subiekt nexo and Fakturownia integrations. Need a custom Allegro flow, an integration or a Medusa store? Write to kontakt@koda.plus.

Trademarks

Allegro and the Allegro logo are trademarks of their owner, used here only to identify the marketplace this plugin connects to. This is an independent integration built on the public Allegro REST API, not affiliated with or endorsed by Allegro.

License

MIT, see LICENSE.

Changelog

0.3.0 (unreleased)

Opaque event ids in the order import; demo mode only with Copy to clipboarddemo: true and demo orders that are never placed or paid; gross prices only for prices and drafts; tokens kept on configuration mistakes; reads that never write; writes only from the admin or a server; the Copy to clipboardkoda.integration/1 contract with embeddable product and order cards and deep links; events for your alerts; type declarations. Full list in CHANGELOG.md.

You may also like

Browse all integrations

Build your own

Develop your own custom integration

Build your own integration with our API to speed up your processes. Make your integration available via npm for it to be shared in our Library with the broader Medusa community.

gift card interface

Ready to build your custom commerce setup?