createSellersWorkflow creates the Seller, links its regions, and invites its first team member.
Before you begin
You need the following in place:- A Mercur server with
@mercurjs/coreinstalled throughwithMercur() - A default region set on your Medusa store, since every new store links to it
Create the store
1
Add a route that runs the workflow
Create an API route and run the workflow against the request’s container. Each entry in The store gets the handle
sellers needs a member.email: the workflow sends that address an invite with the role_seller_administration role.src/api/admin/import-sellers/route.ts
acme-supplies and links to the default region plus reg_01JD8Q1234567.2
Open the store
New stores start in Approval stamps
pending_approval. Run approveSellerWorkflow to open one, or pass status: "open" in the seller input when you import stores you’ve already vetted.approved_at and emits seller.approved.3
Let the owner accept the invite
The workflow emits
member_invite.created with the invite’s id, token, and expires_at. Send the token to the invitee from a subscriber. When they accept it through acceptMemberInviteWorkflow, they join as the store’s owner. Manage the team shows both the subscriber and the accept call.Attach custom data with additional_data
The workflow passesadditional_data to its sellersCreated hook. Use the hook to save data that belongs to your extension, such as a referral code, without changing the workflow.
src/workflows/hooks/sellers-created.ts
additional_data: { referral_code: "SPRING25" } next to sellers in the workflow input to reach this hook. The workflow also has a validate hook that runs before anything is written, so you can throw there to reject the input.
Create the owner membership directly
createSellersWorkflow invites the owner. When the person already signed in, for example in a custom registration route, run createSellerAccountWorkflow instead. It creates the store in pending_approval and adds the member as owner in one call.
member actor type. It also accepts address, professional_details, and payment_details, and writes each one when present.
Handle a failed creation
The workflow rolls back every step when one fails. These inputs fail:- Duplicate
name,email,handle, orexternal_id: the unique indexes reject the insert - Invalid
handle: a handle with characters that aren’t URL safe fails withINVALID_DATA - Unknown region: a
region_idsentry that doesn’t exist fails withNOT_FOUND