SimpleSitemap.com API: How to Automate Sitemap Generation
SimpleSitemap.com API: How to Automate Sitemap Generation
Automating sitemap generation saves time and ensures your sitemap stays up-to-date as your website grows. SimpleSitemap.com offers a powerful REST API that makes it easy to integrate automated sitemap generation into your workflow, CMS, or application.
In this comprehensive guide, we'll show you how to use SimpleSitemap.com's API to automate sitemap creation.
Why Automate Sitemap Generation?
Benefits of Automation
- Always Current: Sitemaps update automatically when content changes
- Consistency: Ensures sitemaps are generated regularly
- Integration: Works seamlessly with your existing tools
- Scalability: Handle multiple websites efficiently
When to Use the API
- Your website content changes frequently
- You manage multiple websites
- You want scheduled sitemap updates
- You're building a custom application
SimpleSitemap.com API Overview
API Endpoint
The SimpleSitemap.com API endpoint is:
https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/buildRequest Method
GET request with URL parameter
Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| url | string | Yes | The website URL to generate a sitemap for |
Response
- Body: XML sitemap content
Basic API Usage
Simple GET Request
The simplest way to use the API is with a GET request:
curl "https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build?url=https://example.com"JavaScript Example
async function generateSitemap(websiteUrl) {
const apiUrl = `https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build?url=${encodeURIComponent(websiteUrl)}`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const sitemapXml = await response.text();
return sitemapXml;
} catch (error) {
console.error('Error generating sitemap:', error);
throw error;
}
}
// Usage
generateSitemap('https://example.com')
.then(sitemap => {
console.log('Sitemap generated:', sitemap);
})
.catch(error => {
console.error('Failed:', error);
});Python Example
import requests
from urllib.parse import quote
def generate_sitemap(website_url):
api_url = f"https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build"
params = {"url": website_url}
try:
response = requests.get(api_url, params=params)
response.raise_for_status()
return response.text
except requests.exceptions.RequestException as e:
print(f"Error generating sitemap: {e}")
raise
# Usage
sitemap_xml = generate_sitemap("https://example.com")
print(sitemap_xml)Node.js Example
const https = require('https');
const { URL } = require('url');
function generateSitemap(websiteUrl) {
return new Promise((resolve, reject) => {
const apiUrl = new URL('https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build');
apiUrl.searchParams.append('url', websiteUrl);
https.get(apiUrl.toString(), (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
resolve(data);
} else {
reject(new Error(`HTTP error! status: ${res.statusCode}`));
}
});
}).on('error', (error) => {
reject(error);
});
});
}
// Usage
generateSitemap('https://example.com')
.then(sitemap => console.log(sitemap))
.catch(error => console.error('Error:', error));Advanced Integration Examples
WordPress Plugin Integration
Create a WordPress function to automatically generate and update sitemaps:
Scheduled Updates with Cron
Automate sitemap generation on a schedule:
#!/bin/bash
# Run daily at 2 AM
WEBSITE_URL="https://example.com"
API_URL="https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build"
SITEMAP_PATH="/var/www/html/sitemap.xml"
curl "${API_URL}?url=${WEBSITE_URL}" > ${SITEMAP_PATH}
# Optional: Submit to Google Search Console API
# (requires authentication setup)GitHub Actions Workflow
Automate sitemap generation in CI/CD:
name: Generate Sitemap
on:
schedule:
- cron: '0 2 * * *' # Daily at 2 AM
workflow_dispatch:
jobs:
generate-sitemap:
runs-on: ubuntu-latest
steps:
- name: Generate Sitemap
run: |
curl "https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build?url=https://example.com" > sitemap.xml
- name: Commit and Push
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add sitemap.xml
git commit -m "Update sitemap" || exit 0
git pushNode.js Express Server
Create an API endpoint that generates sitemaps:
const express = require('express');
const axios = require('axios');
const app = express();
app.get('/api/generate-sitemap', async (req, res) => {
const { url } = req.query;
if (!url) {
return res.status(400).json({ error: 'URL parameter is required' });
}
try {
const apiUrl = `https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build?url=${encodeURIComponent(url)}`;
const response = await axios.get(apiUrl);
res.setHeader('Content-Type', 'application/xml');
res.send(response.data);
} catch (error) {
res.status(500).json({ error: 'Failed to generate sitemap' });
}
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});Error Handling
Common Errors and Solutions
Error: Invalid URL
- Include protocol (http:// or https://)
- URL encode special characters
Error: Timeout
- Implement retry logic with exponential backoff
- Consider splitting large sites into multiple sitemaps
Error: Rate Limiting
- Cache sitemap results
- Don't generate sitemaps too frequently
Error Handling Example
async function generateSitemapWithRetry(websiteUrl, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const apiUrl = `https://simplesitemapbackend-651775934823.us-central1.run.app/sitemap/build?url=${encodeURIComponent(websiteUrl)}`;
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return await response.text();
} catch (error) {
if (attempt === maxRetries) {
throw error;
}
// Wait before retry (exponential backoff)
await new Promise(resolve => setTimeout(resolve, Math.pow(2, attempt) * 1000));
}
}
}Best Practices
1. Cache Results
Don't generate sitemaps on every request. Cache the results:
const cache = new Map();
const CACHE_DURATION = 24 * 60 * 60 * 1000; // 24 hours
async function getCachedSitemap(websiteUrl) {
const cacheKey = websiteUrl;
const cached = cache.get(cacheKey);
if (cached && Date.now() - cached.timestamp < CACHE_DURATION) {
return cached.sitemap;
}
const sitemap = await generateSitemap(websiteUrl);
cache.set(cacheKey, { sitemap, timestamp: Date.now() });
return sitemap;
}2. Validate XML
Always validate the XML before saving:
import xml.etree.ElementTree as ET
def validate_sitemap_xml(xml_string):
try:
ET.fromstring(xml_string)
return True
except ET.ParseError:
return False
sitemap_xml = generate_sitemap("https://example.com")
if validate_sitemap_xml(sitemap_xml):
# Save sitemap
pass3. Handle Large Sites
For sites with more than 500 pages, consider splitting:
async function generateMultipleSitemaps(baseUrl, sections) {
const sitemaps = [];
for (const section of sections) {
const url = `${baseUrl}/${section}`;
const sitemap = await generateSitemap(url);
sitemaps.push({ section, sitemap });
}
return sitemaps;
}API Documentation
For complete API documentation, visit:
SimpleSitemap.com API Documentation
Conclusion
The SimpleSitemap.com API makes it easy to automate sitemap generation in your applications. Whether you're building a CMS integration, setting up scheduled updates, or creating a custom solution, the API provides a simple, reliable way to generate sitemaps programmatically.
Key takeaways:
- ✅ Works with any programming language
- ✅ No authentication required
- ✅ Fast and reliable
- ✅ Perfect for automation
Start automating your sitemap generation today!
---
Related Articles: