Automated Sitemap Generation
AutomationKeep your XML sitemap automatically updated using webhooks, GitHub Actions, or scheduled tasks whenever your content changes.
Your sitemap should stay fresh as your content changes. Manual updates are error-prone and easy to forget. Automation ensures search engines always have the latest information about your site structure.
Always Current
Sitemap updates automatically when content changes
Better SEO
Search engines discover new content faster
Zero Maintenance
Set it up once and forget about it
/api/admin/sitemap/generate
Requires admin authentication. Returns the number of URLs generated and timestamp.
Example Response:
{ "success": true, "urlCount": 42, "lastGenerated": "2024-01-15T10:30:00.000Z" }
Perfect for sites deployed from GitHub. Automatically regenerate your sitemap when you deploy new content or on a schedule.
1. Create Workflow File
Create .github/workflows/sitemap.yml
in your repository:
name: Update Sitemap on: # Trigger after successful deployment workflow_run: workflows: ["Deploy"] types: [completed] branches: [main] # Or run on a schedule (daily at 2 AM UTC) schedule: - cron: '0 2 * * *' # Allow manual trigger workflow_dispatch: jobs: update-sitemap: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} steps: - name: Trigger Sitemap Generation run: | curl -X POST \ -H "Authorization: Bearer ${{ secrets.SITEMAP_API_KEY }}" \ -H "Content-Type: application/json" \ -d '{}' \ "${{ secrets.SITE_URL }}/api/admin/sitemap/generate"
2. Add Repository Secrets
Go to your GitHub repository → Settings → Secrets and variables → Actions:
SITE_URL
→https://yourdomain.comSITEMAP_API_KEY
→Your admin API keyIf you're using Coolify for deployment, you can set up scheduled tasks directly in the Coolify dashboard.
1. Access Scheduled Tasks
- Open your Coolify dashboard
- Navigate to your application
- Go to "Scheduled Tasks" tab
- Click "Add New Task"
2. Configure the Task
curl -X POST \ -H "Authorization: Bearer $SITEMAP_API_KEY" \ -H "Content-Type: application/json" \ -d '{}' \ "$SITE_URL/api/admin/sitemap/generate"
3. Set Environment Variables
Add these to your application's environment variables in Coolify:
SITE_URL
→https://yourdomain.comSITEMAP_API_KEY
→Your admin API keySet up webhooks to regenerate your sitemap when content changes in your CMS, forms are submitted, or other events occur.
Webhook Endpoint Setup
Configure your CMS or service to send a POST request to:
https://yourdomain.com/api/admin/sitemap/generate
Required Headers
All webhook requests must include these headers:
Authorization
→Bearer your-sitemap-api-key
Content-Type
→application/json
Postman Setup
Test your webhook endpoint using Postman:
1. Create New Request
- • Method:
POST
- • URL:
https://yourdomain.com/api/admin/sitemap/generate
2. Set Headers
3. Set Body
Select "raw" and "JSON" format, then use:
{}
4. Expected Response
{ "success": true, "urlCount": 42, "lastGenerated": "2024-01-15T10:30:00.000Z" }
Common Webhook Sources
Content Management
- • Strapi
- • Contentful
- • Sanity
- • Ghost
E-commerce
- • Shopify
- • WooCommerce
- • Medusa
- • Saleor
Example: Strapi Webhook
- Go to Settings → Webhooks in your Strapi admin
- Click "Create new webhook"
- Set URL to your sitemap generation endpoint
- Add Authorization header with your API key
- Select events: Entry create, update, delete
Option 1: API Key (Recommended)
Create a dedicated API key for sitemap generation:
# Add to your environment variables SITEMAP_API_KEY=your-secure-api-key-here # Use in Authorization header Authorization: Bearer your-secure-api-key-here
Option 2: Session-Based
Use your existing admin session cookies (less suitable for automation).
Manual Test
Test the endpoint manually using curl:
curl -X POST \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{}' \ "https://yourdomain.com/api/admin/sitemap/generate"
Verify Results
- Check the API response for success status
- Visit
/sitemap.xml
to see the updated sitemap - Check the admin panel for the last generation timestamp
- Monitor your automation logs for any errors
✅ Do
- • Set up monitoring for failed generations
- • Use secure API keys with limited scope
- • Test in staging before production
- • Set reasonable rate limits
- • Monitor sitemap file size
❌ Don't
- • Generate sitemaps too frequently (1 hour)
- • Expose API keys in client-side code
- • Skip error handling in automation
- • Forget to update webhooks when URLs change
- • Generate sitemaps for every minor change
Common Issues
401 Unauthorized
Check your API key or authentication headers. Ensure SITEMAP_API_KEY is set in your environment variables.
Invalid Input: Expected Object, Received Undefined
Include an empty JSON object {}
in the request body, even if no data is needed. Set Content-Type to application/json.
500 Server Error
Check server logs and database connectivity. Verify SITEMAP_API_KEY environment variable is configured.
Webhook Not Triggering
Verify webhook URL and check CMS webhook logs. Ensure the Authorization header is properly formatted.