A collection of administrative scripts for managing bulk operations in Medusa v2. This repository contains tools we use to efficiently manage our Medusa store, shared with the community.
Currently includes scripts for:
- Tax Region Management - Bulk create tax regions for multiple countries
- VAT Rate Configuration - Set default VAT rates across all regions
- Service Zone Management - Create and update shipping service zones with flexible country selection
More bulk operation scripts will be added as we build them for our store.
- Node.js (v18 or higher)
- Medusa v2 server
- Admin access to your Medusa instance
- Install dependencies:
npm install- Create a
.envfile in the project root:
cp .env.example .env- Configure your environment variables (see Authentication)
Medusa v2 uses secret API keys for admin operations.
-
Generate a Secret API Key:
- Log into your Medusa Admin dashboard
- Go to Settings → Developer → Secret API Keys
- Create a new API key (you can only have one active key per user)
- Copy the key immediately (it's only shown once)
-
Add to
.envfile:
MEDUSA_API_URL=https://your-medusa-instance.com
MEDUSA_API_KEY=sk_your_secret_key_hereImportant: Secret API keys use Authorization: Basic header format in Medusa v2, which these scripts handle automatically.
Creates tax regions for all EU countries plus Switzerland, Norway, Ukraine, Vatican City, and Monaco.
node create-eu-tax-regions.jsWhat it does:
- Creates 33 tax regions with country codes
- Sets the default tax provider (
tp_system) - Skips regions that already exist
Countries included:
- EU: AT, BE, BG, HR, CY, CZ, DK, EE, FI, FR, DE, GR, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, RO, SK, SI, ES, SE
- Non-EU: CH, GB, MC, NO, UA, VA
Sets the default VAT rate for all EU tax regions.
node set-eu-tax.jsWhat it does:
- Fetches all tax regions (with pagination)
- Sets 5% VAT as the default tax rate for each EU country
- Skips regions that already have a default tax rate
Configuration:
To change the VAT rate, edit the TAX_RATE constant in set-eu-tax.js:
const TAX_RATE = 5 // Change this to your desired rateCreates or updates a shipping service zone for a specific warehouse (stock location) with an interactive terminal interface. Service zones define which geographical areas can be served from a particular warehouse.
node create-service-zone.jsInteractive Steps:
The script will guide you through:
- Select Stock Location - Choose from your existing warehouses
- Fulfillment Set - Create a new one or enter an existing ID
- Service Zone Name - Enter a name for your zone
- Country Selection Mode - Choose how to select countries:
- Include specific countries
- Include all countries
- Exclude specific countries
- Select Countries - Pick from:
- EU Countries (predefined list)
- All available countries from your store
- Manual entry (comma-separated codes)
- Confirm - Review summary and proceed
Features:
- ✅ Interactive prompts with arrow key navigation
- ✅ Checkbox selection for multiple countries
- ✅ Auto-creates fulfillment sets if needed
- ✅ Updates existing zones or creates new ones
- ✅ Validates all inputs
- ✅ Shows summary before applying changes
Example Flow:
📦 Step 1: Select Stock Location (Warehouse)
? What would you like to do? Use existing stock location
? Select a stock location: European Warehouse (Wieliczka, PL)
✅ Selected: European Warehouse
📋 Step 2: Get Fulfillment Set
? Create a new fulfillment set for European Warehouse? Yes
? Enter fulfillment set name: Shipping
? Select fulfillment set type: Shipping (default)
✅ Created fulfillment set: fset_01XXXXX
🗺️ Step 3: Service Zone Configuration
? Enter service zone name: EU Zone
🌍 Step 4: Country Selection
? How do you want to select countries? Include specific countries
📍 Step 5: Select Countries
? Which countries would you like to work with? EU Countries (predefined list)
? Select countries to include: (Use arrow keys and space to select)
◉ Austria (AT)
◉ Belgium (BE)
◉ Bulgaria (BG)
...
✅ Including 27 countries
📝 Summary:
Warehouse: European Warehouse
Fulfillment Set: fset_01XXXXX
Zone Name: EU Zone
Countries: 27 countries
Codes: at, be, bg, hr, cy, cz, dk, ee, fi, fr...
? Proceed with creating/updating this service zone? Yes
✅ Successfully created service zone!
The countries.js file contains a centralized list of European countries used across all scripts:
import { EU_COUNTRIES, EU_COUNTRY_CODES } from './countries.js'
// EU_COUNTRIES: Array of objects with code and name
// EU_COUNTRY_CODES: Array of just country codesThis ensures consistency across all scripts and makes it easy to update country lists in one place.
| Variable | Required | Description |
|---|---|---|
MEDUSA_API_URL |
Yes | Base URL of your Medusa instance |
MEDUSA_API_KEY |
Yes | Secret API key for authentication |
# Medusa Instance
MEDUSA_API_URL=https://your-medusa-instance.com
# Secret API Key
MEDUSA_API_KEY=sk_your_secret_api_key_here- Create tax regions:
node create-eu-tax-regions.js- Set VAT rates:
node set-eu-tax.jsProblem: Scripts fail with "Request failed with status code 401"
Solution:
- Verify your API key is correct in
.env - Ensure the API key hasn't been revoked
- Generate a new API key from Medusa Admin (Settings → Developer → Secret API Keys)
- Remember: You can only have one active secret key per user
Problem: "Provider is required when creating a non-province tax region"
Solution: This is handled automatically by the scripts. The provider_id: "tp_system" is set for all tax regions.
Problem: Cannot set default tax rate because one already exists
Solution: Each tax region can only have one default tax rate. If you need to update it:
- Delete the existing default tax rate via Medusa Admin
- Run the script again
- Never commit
.envfile - It contains sensitive credentials - API keys are sensitive - Treat them like passwords
- Rotate keys regularly - Generate new keys periodically
These scripts are designed for Medusa v2 and use:
Authorization: Basic {api_key}header format for authentication/admin/tax-regionsendpoint for tax region managementprovider_id: "tp_system"as the default tax provider
If you're using Medusa v1, these scripts will not work.
@medusajs/medusa-js(v6.1.10) - Medusa JavaScript SDKdotenv(v17.2.3) - Environment variable management
We welcome contributions! If you have bulk operation scripts that would be useful to the Medusa community, feel free to:
- Open an issue to discuss your idea
- Submit a pull request with your script
- Share feedback on existing scripts
These scripts are actively used to manage our Medusa store. We're sharing them with the community to help others streamline their Medusa operations.
ISC