Overview
Icon for Apaczka.pl

Apaczka.pl

20+ Polish carriers with live rates

Apaczka.pl for Medusa

Installation · Configuration · All options · What it does · Demo mode · Sandbox · Storefront

Requirements

  • Medusa 2.22 or newer, Node.js 20.19+ or 22.12+
  • An Apaczka.pl account with WebAPI access (Apaczka panel → Settings → API)

Installation

npm install @bitshaft/medusa-plugin-apaczka

The package has no runtime dependencies of its own. It uses the Medusa packages your app already has (Copy to clipboard@medusajs/framework, Copy to clipboard@medusajs/medusa, the admin SDK, UI and icons, Copy to clipboard@medusajs/js-sdk and Copy to clipboard@tanstack/react-query) as peer dependencies.

Register it (Configuration) and run the migrations:

npx medusa db:migrate

Trying a local build

To test unreleased changes in an app before publishing:

# in plugins/medusa-plugin-apaczka
npm run build
npx medusa plugin:publish # publishes to the local package registry
# in your Medusa app
npx medusa plugin:add @bitshaft/medusa-plugin-apaczka

Copy to clipboardnpm run dev (Copy to clipboardmedusa plugin:develop) rebuilds and republishes on every change.

Configuration

The plugin (shipment records, admin UI, webhooks, jobs) and the fulfillment provider (rates, labels) share one options object:

// medusa-config.ts
import { defineConfig, loadEnv } from "@medusajs/framework/utils"
loadEnv(process.env.NODE_ENV || "development", process.cwd())
const apaczka = {
appId: process.env.APACZKA_APP_ID,
appSecret: process.env.APACZKA_APP_SECRET,
environment: (process.env.APACZKA_ENV as "production" | "sandbox") ?? "production",
sender: {
// Medusa stock locations have no e-mail or contact person; set them here.
contactPerson: "Jane Doe",
email: "warehouse@example.com",
},
webhooks: { backendUrl: process.env.MEDUSA_BACKEND_URL },
}
export default defineConfig({
projectConfig: {/* … */},
plugins: [{ resolve: "@bitshaft/medusa-plugin-apaczka", options: apaczka }],

If Copy to clipboardappId or Copy to clipboardappSecret is missing, or an option is invalid, Medusa still starts. The plugin stays disabled, logs one line (Copy to clipboard[apaczka] Disabled: …) and shows the reason on the Apaczka page in the admin menu, under the tabs. Nothing is sent to Apaczka until you fix the options and restart.

Every option is described in docs/configuration.md: pricing, parcels, pickups, COD, insurance, notifications, tracking, caching and code hooks.

Environment variables

The plugin reads only its options. These are the variables the example above maps into them; copy .env.template to start.

Variable Used for Copy to clipboardAPACZKA_APP_ID Copy to clipboardappId Apaczka panel → Settings → API Copy to clipboardAPACZKA_APP_SECRET Copy to clipboardappSecret Keep it out of git. Used only to sign requests and verify webhooks, never logged Copy to clipboardAPACZKA_ENV Copy to clipboardenvironment Copy to clipboardsandbox or Copy to clipboardproduction. Sandbox and production credentials are different Copy to clipboardMEDUSA_BACKEND_URL Copy to clipboardwebhooks.backendUrl Public URL of your backend, for push tracking Copy to clipboardAPACZKA_SANDBOX_APP_ID sandbox tests only See Testing against the Apaczka sandbox Copy to clipboardAPACZKA_SANDBOX_APP_SECRET sandbox tests only Copy to clipboardAPACZKA_SANDBOX_WRITE sandbox tests only Copy to clipboardtrue also creates and cancels a real sandbox order

Create shipping options

  1. In the admin, open Settings → Locations, pick a location and enable the apaczka fulfillment provider.
  2. In a shipping zone, click Create option, choose the apaczka provider and pick a service, such as "InPost Paczkomat" or "DPD Kurier — COD" (service names come from your Apaczka account).
  3. Choose a Fixed price or Calculated (a live Apaczka quote, with your pricing rules applied).

The Settings tab of the Apaczka page shows whether the connection works and which services your account has.

Add the point picker to your storefront

For locker and pickup-point services, the customer has to choose a point. Copy the storefront kit into your storefront and send the point with the shipping method:

await sdk.store.cart.addShippingMethod(cart.id, { option_id, data: { point_id: "WAW01M" } })

What it does

  • Every service on your account. Read from Apaczka, never hardcoded, and refreshed daily. Each service is available as a standard, cash-on-delivery and return shipping option.
  • Live rates or flat rates per shipping option, with markups, rounding, free-shipping thresholds, per-service overrides and a fallback price so checkout keeps working if Apaczka is down.
  • Parcel lockers and pickup points. Point validation at checkout (including COD support at the point) and a map-and-list point picker for the storefront.
  • Labels automatically or by hand. PDF or ZPL for thermal printers. In manual mode staff can adjust parcels, service, pickup, COD, insurance and the point before creating the shipment.
  • Courier pickups for one shipment or many (batch), using the pickup days Apaczka offers.
  • Return labels created as soon as a return is requested.
  • Tracking by signed webhooks with polling as a backup. Fulfillments are marked shipped and delivered in Medusa, and events are emitted for your own notifications.
  • Apaczka page in the admin menu with every shipment in one list: search by waybill, Apaczka or order number, filters by status and returns, labels, tracking refresh, a courier pickup or a hand-over protocol for several shipments at once, a Settings tab with a connection check and the options in use, and a Guide tab. Plus a panel on each order page. In Polish and English.
  • Multi-warehouse. The sender address comes from each stock location, with per-location overrides.
  • Built to be safe. HMAC request signing, webhook signature verification against the raw request body, no retries on order creation (so no duplicate orders), every workflow step undone on failure, money handled as integers, and secrets masked in logs and never returned by the admin API.

What it does not do

  • No customer notifications of its own. The plugin emits events (Copy to clipboardapaczka.shipment.*) and can turn on Apaczka's own e-mail/SMS notifications. Sending your own e-mails or texts is up to your subscribers.
  • Nothing the Apaczka API does not offer. No invoices or billing, no claims handling, no address book sync. Those stay in the Apaczka panel.
  • One Apaczka account per Medusa instance. Each stock location can have its own sender address, but all shipments go through the same account.
  • No live currency conversion. Apaczka prices in PLN. For other cart currencies you set fixed rates (Copy to clipboardpricing.exchangeRates) or use flat-rate options.
  • No storefront code in the npm package. The point picker is copy-in source in storefront/, so your storefront does not pull in Medusa's backend packages.

How it works

Checkout Fulfillment Carrier Medusa
──────── ─────────── ─────── ──────
price (live/flat) ──► Apaczka order + label ──► webhook / polling ──► shipped → delivered
point validated (auto or from admin) status changes apaczka.* events
  • Creating shipments. With Copy to clipboardshipmentCreation: "auto" (the default), the Apaczka order is created when you create a fulfillment in Medusa, and the label is attached to it. With Copy to clipboard"manual", the fulfillment is created first and staff create the shipment from the Apaczka shipments panel on the order page. That lets them check the price and adjust parcels, pickup, COD or the point first.
  • Parcel weight. Parcels are weighed from the variants' Copy to clipboardweight (grams by default, Copy to clipboardparcel.weightUnit). A variant without a weight counts as Copy to clipboardparcel.defaultItemWeightKg (1 kg) per unit. The shipment form warns about such products, and Settings → Parcel weight lists every variant without a weight and can hold automatic shipments that contain one, so a person checks the parcel before the carrier gets a guessed weight.
  • Sender address. Built from the stock location's address, merged with Copy to clipboardsender (global defaults) and Copy to clipboardsenderByLocation (per location).
  • Cash on delivery. Each parcel collects only what is still unpaid. Split orders are divided across parcels so the total is never collected twice.
  • What runs where. Medusa's fulfillment provider can't see payments, other shipments of the order or the full stock location. So COD shipments, and shipments whose sender needs the stock location's address, are created by the plugin a moment after the fulfillment, through the same workflow as the order panel. If Apaczka rejects one, the reason shows in the order panel with a button to retry.
  • Returns. Return shipping options work like outbound ones. The return label is created right after the return is requested (or by hand in manual mode).
  • Tracking. Apaczka pushes signed status updates to Copy to clipboardPOST /hooks/apaczka/tracking. A job polls active shipments every 30 minutes as a backup. The plugin marks fulfillments shipped and delivered, and emits events you can subscribe to.
  • Cancellation. Cancelling a fulfillment in Medusa cancels the Apaczka order. Apaczka refuses once the carrier has the parcel, and the plugin shows that message.
  • Parcel points. Each carrier's list (tens of thousands of lockers) is stored in the database, in Copy to clipboardapaczka_point, never held in memory. A list older than Copy to clipboardpointsTtlMinutes is refreshed in the background while searches keep using it; only a carrier with no list yet makes the first search wait. One sync per list runs at a time, even across processes, and a failed sync is retried after 15 minutes. Settings → Parcel points shows every list and can sync one now. Details in docs/parcel-points.md.

Webhooks

Set Copy to clipboardwebhooks.backendUrl and every order is created with its own webhook URL. You can also paste Copy to clipboardhttps://<your-backend>/hooks/apaczka/tracking once into the Apaczka panel (Settings → WebAPI). Requests are rejected unless their HMAC signature matches your app secret.

Events

Event When Copy to clipboardapaczka.shipment.created An Apaczka order was created for a fulfillment Copy to clipboardapaczka.shipment.status_changed Any status change (Copy to clipboardstatus, Copy to clipboardprevious_status) Copy to clipboardapaczka.shipment.shipped The carrier took the parcel Copy to clipboardapaczka.shipment.ready_for_pickup Waiting in a locker or pickup point Copy to clipboardapaczka.shipment.delivered Delivered Copy to clipboardapaczka.shipment.exception Failed delivery attempt, notice left, unknown status Copy to clipboardapaczka.shipment.returned Returned to sender (including uncollected parcels) Copy to clipboardapaczka.shipment.canceled Canceled Copy to clipboardapaczka.pickup.booked A courier pickup was booked

// src/subscribers/parcel-ready.ts — e.g. text the customer
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
export default async function parcelReady({ event }: SubscriberArgs<{ order_id: string; tracking_url: string }>) {
// send an SMS / e-mail with event.data.tracking_url
}
export const config: SubscriberConfig = { event: "apaczka.shipment.ready_for_pickup" }

Customizing

Most behaviour is set through options: pricing per service, parcel sizing, pickup windows, COD payout account, insurance, Apaczka's own e-mail/SMS notifications, label format, content templates, and which services appear in the admin.

For anything else there are code hooks, so you don't need a fork:

const apaczka = {
// …
// Your own box-packing logic
buildParcels: ({ items, options }) => [{ dimension1: 40, dimension2: 30, dimension3: 20, weight: 3 }],
// Edit the payload right before it is priced or sent
transformOrder: (order, { purpose, isReturn }) => ({ ...order, comment: isReturn ? "RMA" : order.comment }),
}

The workflows are exported for use in your own code:

import {
createApaczkaShipmentWorkflow,
bookApaczkaPickupWorkflow,
syncApaczkaTrackingWorkflow,
} from "@bitshaft/medusa-plugin-apaczka/workflows"
await createApaczkaShipmentWorkflow(container).run({
input: { fulfillment_id, overrides: { parcels: [{ weight: 2, length: 30, width: 20, height: 10 }] } },
})

You can also pass Copy to clipboardadditional_data.apaczka when creating a fulfillment through Medusa's API: Copy to clipboard{ defer: true } skips automatic creation, and Copy to clipboard{ overrides } adjusts the shipment.

API

Route Copy to clipboardGET /store/apaczka/points?type=INPOST&q=&lat=&lng=&cod= Search parcel points (stored in the database) Copy to clipboardGET /store/apaczka/points?type=INPOST&bbox=w,s,e,n Parcel points inside a map area (up to Copy to clipboardlimit=500) Copy to clipboardGET /store/apaczka/points/clusters?type=INPOST&bbox=w,s,e,n&zoom=6 A zoomed-out map's points, grouped into clusters with counts Copy to clipboardGET /store/apaczka/points/:type/:id One point Copy to clipboardPOST /hooks/apaczka/tracking Apaczka push tracking (signed) Copy to clipboardGET /admin/apaczka/status Connection check and configuration summary Copy to clipboardGET /admin/apaczka/points Stored parcel point lists: count, last sync, state Copy to clipboardPOST /admin/apaczka/points/sync Sync one carrier's points now (Copy to clipboard{ type, country_code }) Copy to clipboardGET /admin/apaczka/services Services, additional options and package types Copy to clipboardGET /admin/apaczka/shipments?order_id=&q=&status= Shipments with tracking history and order numbers Copy to clipboardPOST /admin/apaczka/fulfillments/:id/valuation Price a shipment before creating it Copy to clipboardPOST /admin/apaczka/fulfillments/:id/shipment Create the shipment (with overrides) Copy to clipboardPOST /admin/apaczka/shipments/:id/sync Refresh tracking now Copy to clipboardGET /admin/apaczka/orders/:id/documents/waybill Label (PDF/ZPL), also used as the Medusa label URL Copy to clipboardGET /admin/apaczka/orders/:id/documents/dispatch_code Drop-off code Copy to clipboardPOST /admin/apaczka/turn-in Hand-over (turn-in) confirmation PDF for several shipments Copy to clipboardGET /admin/apaczka/pickup-hours?postal_code=&service_id= Available courier pickup days Copy to clipboardPOST /admin/apaczka/pickups Book a courier pickup

Demo mode

To show the plugin without an Apaczka account, set Copy to clipboarddemo: true (no Copy to clipboardappId or Copy to clipboardappSecret needed):

{ resolve: "@bitshaft/medusa-plugin-apaczka", options: { demo: true } }

A built-in client then answers every call itself and nothing is sent to Apaczka:

  • Services: five sample services (InPost Paczkomat and Kurier, DPD Classic and Pickup, Pocztex Kurier, IDs 9101–9105) that become shipping options as usual, with COD and return variants.
  • Prices: a base price per parcel, more per started kilogram above 1 kg and for COD; gross is net + 23% VAT.
  • Parcel points: eight sample InPost and DPD points in Polish cities, for the storefront point picker.
  • Shipments: created from fulfillments or the order page, with a Copy to clipboardDEMO… waybill number, a price, a PDF (or ZPL) label marked as a demo, a drop-off code, courier pickups and hand-over protocols.
  • Tracking moves on by itself: picked up after 2 minutes, at the sorting centre after 5, on the way after 10, delivered after 20. Every fifth shipment has a failed delivery attempt first and is delivered 10 minutes later. "Refresh tracking" shows the progress at once; the fulfillment is marked shipped and delivered like with real tracking.
  • Cancellation works only in the first 2 minutes, before the carrier takes the parcel.

Real parcel points in demo mode

With Copy to clipboardlivePoints: true, the demo uses your account's real parcel points, so customers pick real lockers on the map, while everything else stays sample data:

options: { demo: true, livePoints: true, appId: process.env.APACZKA_APP_ID, appSecret: process.env.APACZKA_APP_SECRET }

The points request is the only call that reaches Apaczka. Services, prices, shipments, labels, pickups and tracking stay in the demo client, which has no way to send anything else, so no real shipment can ever be created. Stored sample points are replaced by the real lists on first use.

Apaczka keys can't be limited to reading points, so the plugin keeps them inside that one request: the client, the module and the provider only hold placeholders, so a logged object or an admin response can't contain them. The demo store therefore also rejects real Apaczka webhooks. Keep the keys in server-side environment variables only.

The admin page shows a "Demo mode" bar and the Settings tab shows the Copy to clipboarddemo environment. Demo orders are kept in memory; after a restart their details are rebuilt from the order ID, so existing shipments keep working. Don't use demo mode in production: the shipments are not real.

Testing against the Apaczka sandbox

Use Copy to clipboardenvironment: "sandbox" with sandbox credentials while developing. Production orders are real orders with real couriers and invoices.

  1. Ask Apaczka support for sandbox access. The sandbox host (Copy to clipboardpanel-sandbox.apaczka.pl) may only accept requests from allowlisted IP addresses. If requests time out, check that first.
  2. Create API credentials in the sandbox panel. They differ from production.
  3. Run the read-only checks (signing, service structure, valuation, points):
APACZKA_SANDBOX_APP_ID=... APACZKA_SANDBOX_APP_SECRET=... npm run test:sandbox
  1. Optionally, also create and cancel a real sandbox order:
APACZKA_SANDBOX_WRITE=true APACZKA_SANDBOX_APP_ID=... APACZKA_SANDBOX_APP_SECRET=... npm run test:sandbox
  1. To try the whole flow, point a Medusa app at the sandbox (Copy to clipboardAPACZKA_ENV=sandbox), create a fulfillment and check the order panel.

Sandbox limitations (from Apaczka): Copy to clipboardtracking/ and Copy to clipboarddispatch_code/ are not available, Copy to clipboardpoints/ may time out, the service list is smaller and its IDs differ from production, and courier pickups through the API must be enabled on the account by Apaczka support.

Troubleshooting

Problem Fix "Invalid signature" / settings page shows not connected Check Copy to clipboardappId/Copy to clipboardappSecret, and that Copy to clipboardenvironment matches the credentials. Sandbox and production keys are different. Shipping options fail at checkout A calculated option failing makes Medusa fail the whole list. Set Copy to clipboardpricing.fallbackAmount, and make sure the cart has a full shipping address. "Apaczka prices are in PLN, but the cart is in EUR" Add Copy to clipboardpricing.exchangeRates: { eur: 0.23 }, or use fixed prices for that currency. Shipment stays "Not created" with a sender-address reason Fill in the stock location's address, or set Copy to clipboardsender / Copy to clipboardsenderByLocation. COD orders are rejected Set Copy to clipboardcod.bankAccount (IBAN) or Copy to clipboardcod.bankAccountId. Courier booking fails Ask Apaczka support to enable "pickup via API" on your account. No tracking updates Check the webhook URL on the settings page. Polling also needs the shipment to have a tracking number. Log says Copy to clipboard[apaczka] Disabled: … Options are missing or invalid. The line names the fields; fix them and restart.

Development

See docs/development.md for the code layout, conventions and tests, and the repository guide for the shared tooling.

License

MIT © Bitshaft

Built and maintained by Bitshaft, a Medusa and e-commerce engineering studio. Need help with an implementation or a custom integration? Get in touch.

Apaczka and Apaczka.pl are trademarks of Alsendo sp. z o.o. This plugin is an independent integration built on the public Apaczka WebAPI v2. See TRADEMARKS.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?