A simple, lightweight tool to bulk import topics and categories into Discourse forums from CSV files.
- ✅ Bulk import topics from CSV files
- ✅ Auto-create categories and subcategories
- ✅ Support for tags and topic pinning
- ✅ Rate limiting to avoid API throttling
- ✅ Environment variable configuration
- ✅ Error handling with detailed feedback
- ✅ Duplicate detection and graceful handling
- Node.js 14+
- A Discourse forum with admin access
- Discourse API key with appropriate permissions
-
Clone the repository:
git clone https://github.com/qabalany/discourse-csv-importer.git cd discourse-csv-importer -
Install dependencies:
npm install
-
Configure environment:
cp .env.example .env # Edit .env with your actual values
Create a .env file with your Discourse settings:
DISCOURSE_URL=https://your-forum.discourse.com
DISCOURSE_API_KEY=your-api-key-here
DISCOURSE_USERNAME=your-admin-username
CSV_FILE=example.csv
REQUEST_DELAY=1000- Go to your Discourse admin panel
- Navigate to API → Keys
- Create a new API key with appropriate permissions
- Copy the key to your
.envfile
Your CSV file should have these columns:
| Column | Required | Description |
|---|---|---|
category |
✅ | Category name (supports subcategories with /) |
topic_title |
✅ | Title of the topic |
post_content |
✅ | Content of the first post |
tags |
❌ | Comma-separated tags |
pinned |
❌ | "yes" to pin the topic |
author |
❌ | Username (defaults to API user) |
category,topic_title,post_content,pinned,author,tags
"General",Welcome Post,"Welcome to our forum!",yes,admin,"welcome,intro"
"Tech/AI",AI Discussion,"Let's discuss AI trends",no,moderator,"ai,tech"
"Support",FAQ,"Frequently asked questions",yes,admin,"faq,help"
- Prepare your CSV file with the required format
- Set your environment variables in
.env - Run the importer:
npm start
📂 Loaded 4 topics from example.csv
✅ Loaded 3 existing categories
🟢 Created category: Tech Discussion
📝 Creating topic: Welcome to Our Forum
✅ Created topic: Welcome to Our Forum
📌 Pinned topic: Welcome to Our Forum
📝 Creating topic: Getting Started Guide
✅ Created topic: Getting Started Guide
📌 Pinned topic: Getting Started Guide
🎉 All topics processed!
The tool handles common scenarios:
- Duplicate topics: Skips existing topics gracefully
- Missing categories: Creates them automatically
- Rate limiting: Includes delays between requests
- API errors: Detailed error messages for troubleshooting
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues:
- Check the Issues page
- Create a new issue with:
- Your Node.js version
- Error messages (remove sensitive data)
- CSV format example
- Thanks to the Discourse team for their excellent API
- Built with axios and csv-parser