medusa-export
v0.0.5
Published
A starter for Medusa plugins.
Downloads
174
Maintainers
Readme
Medusa Plugin: Export
A Medusa v2 plugin that provides data export functionality, allowing you to export data from any Medusa model to CSV format via admin API endpoints.
Features
- ✅ Flexible Model Export: Export data from any Medusa model using remote query
- ✅ CSV Format: Export data in CSV format for easy import into spreadsheets
- ✅ Admin API Endpoint: Simple REST API endpoint for triggering exports
- ✅ Automatic Data Handling: Handles different data types (dates, objects, null values)
- ✅ Error Handling: Comprehensive error handling with meaningful error messages
Quick Start
- Install the plugin:
npm install medusa-export- Add to medusa-config.ts:
import { defineConfig } from "@medusajs/framework/utils"
export default defineConfig({
plugins: [
{
resolve: "medusa-export",
},
],
})- Use the API:
# Export data from a specific model
GET /admin/export/{model_name}
# Example: Export all products
GET /admin/export/product
# Example: Export all customers
GET /admin/export/customer
# Example: Export all orders
GET /admin/export/orderInstallation
Local Development
- Publish the plugin to local registry:
cd medusa-export
npx medusa plugin:publish- Install in your Medusa application:
cd ../your-medusa-app
npx medusa plugin:add medusa-export- Register the plugin in
medusa-config.ts:
import { defineConfig } from "@medusajs/framework/utils"
export default defineConfig({
plugins: [
{
resolve: "medusa-export",
},
],
})API Reference
Export Data
Endpoint: GET /admin/export/{model_name}
Description: Exports all data from the specified Medusa model to CSV format.
Parameters:
model_name(path parameter): The name of the Medusa model to export (e.g.,product,customer,order)
Response:
- Success (200): Returns CSV file with
Content-Type: text/csvandContent-Disposition: attachment - Error (400): Model name is required
- Error (404): No data found in the specified model
- Error (500): Failed to export data
Example Request:
curl -X GET "http://localhost:9000/admin/export/product" \
-H "Authorization: Bearer {admin_token}" \
-o products.csvExample Response:
id,name,description,created_at,updated_at
prod_01...,"Product Name","Product Description","2024-01-01T00:00:00.000Z","2024-01-01T00:00:00.000Z"Usage Examples
Export Products
GET /admin/export/productExport Customers
GET /admin/export/customerExport Orders
GET /admin/export/orderExport Custom Models
If you have custom models in your Medusa application, you can export them as well:
GET /admin/export/{your_custom_model_name}Data Handling
The plugin automatically handles different data types:
- Dates: Converted to ISO 8601 format
- Objects: Serialized as JSON strings
- Null/Undefined: Converted to empty strings
- Strings: Properly escaped and quoted in CSV format
Compatibility
This plugin is compatible with Medusa v2.4.0 and above.
Requirements
- Node.js >= 20
- Medusa v2.4.0+
Development
Build
npm run buildDevelopment Mode
npm run devLicense
MIT
Support
For issues and questions, please open an issue on the repository or contact the maintainers.
