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 clipboard
orders): Allegro to Medusa, every two minutes from the Allegro order event journal, exactly once per checkout form. - Quantities (writer Copy to clipboard
stock): Medusa to Allegro, every 15 minutes, plan first. - Parcel numbers and seller status (writer Copy to clipboard
shipping): Medusa to Allegro, on every fulfillment and shipment and every five minutes. - Invoice PDFs (writer Copy to clipboard
invoices): Medusa to Allegro, when the Fakturownia plugin (or any invoicing tool) announces a document, and every five minutes. - Prices (writer Copy to clipboard
prices): Medusa to Allegro, every hour at minute 52, plan first, inside bounds from metadata. - Draft offers by EAN (writer Copy to clipboard
publish): 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 clipboard
GET /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=guideopens 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 clipboard
writes.<writer>in the options (a hard switch: Copy to clipboardfalsecannot 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 clipboard
breakerThresholdtimes 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 clipboard
metadata.marketplace_order_refbefore 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 clipboard
convertDraftOrderWorkflow(stock reserved, Copy to clipboardorder.placedemitted), 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 clipboard
carriersmap), 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 clipboard
external.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 clipboard
environment: "sandbox"talks to allegro.pl.allegrosandbox.pl. Tokens of one environment are never used against the other. - Demo mode (only with Copy to clipboard
demo: 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 clipboard
allegro.writer.tripped, Copy to clipboardallegro.import.heldand Copy to clipboardallegro.outbox.failed. - Works with Koda Plus hosts through the shared contract Copy to clipboard
koda.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 clipboard
prices.taxInclusive: true).
Installation
1npm 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:
123456789101112131415161718module.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 AllegrodocsUrl: "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:
123ALLEGRO_CLIENT_ID=your-client-idALLEGRO_CLIENT_SECRET=your-client-secretALLEGRO_ENCRYPTION_KEY=base64-encoded-32-bytes
Run the migrations, then open Allegro in the admin sidebar:
1npx 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 clipboard
clientId, Copy to clipboardclientSecret: the Allegro app credentials. - Copy to clipboard
encryptionKey: 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 clipboard
previousEncryptionKeys(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 clipboard
environment(default Copy to clipboardproduction): Copy to clipboardproductionor Copy to clipboardsandbox. - Copy to clipboard
demo(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 clipboard
appName(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 clipboard
docsUrl(default Copy to clipboardhttps://koda.plus): the https address in the User-Agent. - Copy to clipboard
userAgent(default built from Copy to clipboardappNameand Copy to clipboarddocsUrl): the whole User-Agent, when you need to set it yourself. - Copy to clipboard
requestsPerMinute(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 clipboard
timeoutMs(default Copy to clipboard20000): the timeout of one request.
Reading:
- Copy to clipboard
syncEnabled(default Copy to clipboardtrue): the hourly offer sync. - Copy to clipboard
ordersEnabled(default Copy to clipboardtrue): the order journal. - Copy to clipboard
stockLocationIds(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 clipboard
writes.orders, Copy to clipboardwrites.stock, Copy to clipboardwrites.shipping, Copy to clipboardwrites.invoices, Copy to clipboardwrites.prices, Copy to clipboardwrites.publish(default Copy to clipboardfalseeach; 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 clipboardtruein demo mode too; an explicit Copy to clipboardfalsealways wins). The consent asks Allegro only for the scopes of the writers allowed here: Copy to clipboardallegro:api:sale:offers:writefor stock, prices and drafts, Copy to clipboardallegro:api:orders:writefor parcels and invoices. After changing Copy to clipboardwrites, connect the account again; the admin says which scopes are missing. - Copy to clipboard
breakerThreshold(default Copy to clipboard5): consecutive failures after which a writer disarms itself.
Stock writer:
- Copy to clipboard
stockPush(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 clipboard
stockPushCap(default Copy to clipboard50): offers one run may change. - Copy to clipboard
endOffersAtZero(default Copy to clipboardtrue): end the offer of a variant that sold out in Medusa (Allegro cannot set a quantity to zero). Copy to clipboardfalseonly reports it.
Order import:
- Copy to clipboard
orderImport.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 clipboard
orderImport.regionId(default: the first region in PLN). - Copy to clipboard
orderImport.shippingOptionId(default none): a shipping option put on every imported order, so it can be fulfilled without picking one. - Copy to clipboard
orderImport.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 clipboardshippingOptionIdand 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_idto 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 clipboard
orderImport.perRun(default Copy to clipboard25): orders one run creates at most.
Parcels:
- Copy to clipboard
carriers(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 clipboardOTHERwith the provider name.
Invoices:
- Copy to clipboard
invoiceKinds(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 clipboard
prices.priceListId(default: the variant's default price): read the Medusa price from this price list. - Copy to clipboard
prices.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 clipboard
prices.requireFloor(default Copy to clipboardtrue): never change a price without a floor. - Copy to clipboard
prices.maxChangePercent(default Copy to clipboard30): a bigger change is refused, never clamped. - Copy to clipboard
prices.cap(default Copy to clipboard20): offers one run may change. - Copy to clipboard
prices.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_pricesand 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 clipboard
publish.shippingRatesId(required to publish): the id or name of a shipping rates set from the seller panel. - Copy to clipboard
publish.location(required to publish): Copy to clipboard{ city, postCode, province, countryCode }; for Poland Copy to clipboardprovinceis required (for example Copy to clipboardMAZOWIECKIE) and Copy to clipboardpostCodeis Copy to clipboardXX-XXX. - Copy to clipboard
publish.invoice(default Copy to clipboard"VAT"): Copy to clipboardVAT, Copy to clipboardVAT_MARGIN, Copy to clipboardWITHOUT_VATor Copy to clipboardNO_INVOICE. - Copy to clipboard
publish.cap(default Copy to clipboard5): drafts one run may create.
Customer issues:
- Copy to clipboard
issues.returns(default Copy to clipboardtrue): customer returns, with the orders scope. - Copy to clipboard
issues.disputes(default Copy to clipboardfalse, Copy to clipboardtruein demo mode): disputes and claims. Needs Copy to clipboardallegro:api:disputes, which has no read-only variant. - Copy to clipboard
issues.messages(default Copy to clipboardfalse, Copy to clipboardtruein 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.
- 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.
- Optionally do it all first in the sandbox (apps.developer.allegro.pl.allegrosandbox.pl, Copy to clipboard
environment: "sandbox"). - Generate the encryption key (Copy to clipboard
openssl rand -base64 32) and keep it in the environment. - Add the plugin with Copy to clipboard
clientId, Copy to clipboardclientSecret, Copy to clipboardencryptionKey, Copy to clipboardappNameand Copy to clipboarddocsUrl, run Copy to clipboardnpx medusa db:migrateand restart. - Click Connect Allegro account; the seller types the code at allegro.pl/skojarz-aplikacje.
- Run the first offer sync and check that History shows it as OK.
- Review the offers without a product and without a signature; fix signatures or SKUs.
- Read the stock check and run a dry run of the stock plan.
- Allow only the writers you will use in Copy to clipboard
writes, then Connect again so the seller grants the wider scopes. - Arm the order import first, after a dry run in Imported orders; bring older orders in with the catch-up import.
- Arm the stock writer and watch its plan for a day.
- Arm parcels and status; set Copy to clipboard
orderImport.shippingOptionIdor Copy to clipboardcarrierswhen needed. - Arm invoices (with the Fakturownia plugin or your own event).
- Turn on customer issues if you want disputes and messages counted.
- Optionally arm prices, after putting floors in metadata.
- Optionally plan drafts by EAN, after setting Copy to clipboard
publish.shippingRatesIdand 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
- The import reads the Allegro order event journal (Copy to clipboard
GET /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. - Every due row is claimed atomically and looked up in Medusa by Copy to clipboard
metadata.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. - 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.
- Holding the lock Copy to clipboard
marketplace-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). - 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 clipboard
cancelOrderWorkflowrefunds a captured payment and emits Copy to clipboardorder.canceled, so plugins that react to refunds (an invoice correction, for example) see it. - 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.
- A held import emits Copy to clipboard
allegro.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:
123456789101112// src/subscribers/order-placed.ts in your storeimport 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 clipboard
offer-quantity-change-commandper target value (or an Copy to clipboardENDpublication command) for at most Copy to clipboardstockPushCapoffers, 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 clipboard
POST /order/checkout-forms/{id}/shipments), the seller status becomes Copy to clipboardREADY_FOR_SHIPMENT, and Copy to clipboardSENTwhen 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 clipboard
fakturownia.document.issuedand Copy to clipboardfakturownia.document.correctedwith 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.requestedwith 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 clipboard
prices.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 clipboard
INACTIVEdrafts 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 clipboard
writes.shippingor Copy to clipboardwrites.invoiceswas 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.comonly: 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 clipboard
allegro.writer.trippedCopy to clipboard{ writer, failures, message, demo }: the circuit breaker disarmed a writer. - Copy to clipboard
allegro.import.heldCopy to clipboard{ import_id, checkout_form_id, reason_code, demo }: an Allegro order is waiting for a person. - Copy to clipboard
allegro.outbox.failedCopy to clipboard{ outbox_id, writer, checkout_form_id, order_id, demo }: a parcel, status or invoice could not be sent.
123456789// src/subscribers/allegro-alerts.ts in your storeimport 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 clipboard
GET /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 clipboard
POST /admin/allegro/demo/seed: demo mode, build the missing sample data now (202). - Copy to clipboard
POST /admin/allegro/connectand Copy to clipboardPOST /admin/allegro/connect/poll: the device login. Copy to clipboardPOST /admin/allegro/disconnect: forget the tokens. - Copy to clipboard
POST /admin/allegro/syncwith Copy to clipboard{ "what": "offers" | "orders" | "all" }: a sync in the background (202). - Copy to clipboard
GET /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 clipboard
GET /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 clipboard
POST /admin/allegro/writers/:keywith Copy to clipboard{ "armed": true | false }: arm or disarm Copy to clipboardorders, Copy to clipboardstock, Copy to clipboardshipping, Copy to clipboardinvoices, Copy to clipboardpricesor Copy to clipboardpublish(409 with the reason when it cannot be armed). - Copy to clipboard
GET /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/planswith 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 clipboard
GET /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/importswith 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/windowwith 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 clipboard
GET /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: nullfor an order the plugin did not import. - Copy to clipboard
GET /admin/allegro/outbox?writer=shipping|invoices&status=: parcels, statuses and invoices. Copy to clipboardPOST /admin/allegro/outboxwith Copy to clipboard{ writer }: send what is due now. Copy to clipboardPOST /admin/allegro/outbox/:id/retry: retry a failed row. - Copy to clipboard
GET /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 clipboard
GET /admin/allegro/runs: the history, optionally Copy to clipboardkind(offers, orders, stock, prices, import, shipping, invoices, issues, publish). - Copy to clipboard
GET /admin/allegro/products/:id: offers linked to a product. - Copy to clipboard
GET /store/allegro/products/:id: live offers of a product for the storefront. - Copy to clipboard
GET /admin/allegro/integration, Copy to clipboardGET /admin/allegro/integration/summary, Copy to clipboardGET /admin/allegro/integration/attention: the Copy to clipboardkoda.integration/1contract (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 clipboard
GET /admin/allegro/integration: the manifest (mode, configuration, writers armed, widgets, problems). - Copy to clipboard
GET /admin/allegro/integration/summary?entity=order&id=order_...(or Copy to clipboardids=, up to 50; also Copy to clipboardentity=productand 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 clipboardcodfor cash on delivery or Copy to clipboardpaidwhen 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 clipboardlistingfact that links the offer on allegro.pl (the sandbox host in sandbox mode, the plugin page for demo offers). - Copy to clipboard
GET /admin/allegro/integration/attention?scope=orders,products: counters Copy to clipboardimports_attention(red), Copy to clipboardimports_held, Copy to clipboardissues_openand 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 clipboard
allegro.orderfor the zone Copy to clipboardorder.details(hidden for orders without a line) and Copy to clipboardallegro.productfor 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|issueswhen 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).
123456import { 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 clipboard
PUT /sale/offer-quantity-change-commands/{uuid}and Copy to clipboardPUT /sale/offer-publication-commands/{uuid}with Copy to clipboardENDonly (stock), Copy to clipboardPUT /sale/offer-price-change-commands/{uuid}(prices), Copy to clipboardPOST /order/checkout-forms/{uuid}/shipmentsand Copy to clipboardPUT /order/checkout-forms/{uuid}/fulfillment(parcels), Copy to clipboardPOST /order/{uuid}/billing-documents/files(invoices), Copy to clipboardPOST /sale/product-offerswith an Copy to clipboardINACTIVEpublication 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 clipboard
writes, 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 clipboard
invalid_grant(the consent itself is gone) disconnects the account. Copy to clipboardpreviousEncryptionKeysrotates 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-requestheader, 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 clipboard
allegro_*, Copy to clipboardmarketplace_order_refand Copy to clipboardkoda_demoin 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 clipboard
docs/allegro-api-notes.md). Start in the sandbox.
Uninstall
- 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).
- Remove the plugin from Copy to clipboard
medusa-config.tsand the package from Copy to clipboardpackage.json. - The tables Copy to clipboard
allegro_*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. - After a demo: the demo orders (Copy to clipboard
metadata.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
1234npm installnpm testnpm run typechecknpm 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.

