Need to generate XML sitemaps for SEO? This guide covers everything you need to know about creating sitemaps via API, including format requirements, priority settings, and implementation examples in multiple languages.
What is an XML Sitemap?
An XML sitemap is a file that lists all the important URLs on your website that you want search engines to crawl and index. It helps search engines understand your site structure and discover new or updated content more efficiently.
A basic sitemap entry looks like: <url><loc>https://example.com/page</loc></url>
Why Sitemaps Matter for SEO
Sitemaps provide several SEO benefits:
- Faster Indexing: Help search engines discover new pages quickly
- Complete Coverage: Ensure all important pages are found
- Priority Signals: Indicate which pages are most important
- Change Frequency: Tell crawlers how often content updates
Using the Sitemap Generator API
TinyFn provides an endpoint to generate XML sitemaps:
POST https://api.tinyfn.io/v1/generate/sitemap
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"urls": [
{"loc": "https://example.com/", "priority": 1.0, "changefreq": "daily"},
{"loc": "https://example.com/about", "priority": 0.8, "changefreq": "monthly"},
{"loc": "https://example.com/blog", "priority": 0.9, "changefreq": "weekly"}
]
}
{
"xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n <url>\n <loc>https://example.com/</loc>\n <priority>1.0</priority>\n <changefreq>daily</changefreq>\n </url>\n ...\n</urlset>",
"url_count": 3
}
Parameters
| Parameter | Type | Description |
|---|---|---|
urls |
array | Array of URL objects (required) |
urls[].loc |
string | Full URL of the page (required) |
urls[].lastmod |
string | Last modification date (ISO 8601) |
urls[].changefreq |
string | Change frequency: always, hourly, daily, weekly, monthly, yearly, never |
urls[].priority |
number | Priority 0.0 to 1.0 (default: 0.5) |
Code Examples
JavaScript / Node.js
const response = await fetch('https://api.tinyfn.io/v1/generate/sitemap', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
urls: [
{ loc: 'https://mysite.com/', priority: 1.0, changefreq: 'daily' },
{ loc: 'https://mysite.com/products', priority: 0.9, changefreq: 'weekly' },
{ loc: 'https://mysite.com/contact', priority: 0.5, changefreq: 'monthly' }
]
})
});
const { xml } = await response.json();
// Save to sitemap.xml file
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/generate/sitemap',
json={
'urls': [
{'loc': 'https://mysite.com/', 'priority': 1.0},
{'loc': 'https://mysite.com/blog', 'priority': 0.8, 'changefreq': 'daily'},
{'loc': 'https://mysite.com/about', 'priority': 0.6}
]
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
with open('sitemap.xml', 'w') as f:
f.write(data['xml'])
cURL
curl -X POST "https://api.tinyfn.io/v1/generate/sitemap" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"urls": [{"loc": "https://example.com/", "priority": 1.0}]}'
Sitemap Options
- Priority: 0.0 (least important) to 1.0 (most important)
- Change Frequency: How often the page content changes
- Last Modified: When the page was last updated
- Sitemap Index: For sites with 50,000+ URLs
- Image/Video Sitemaps: Specialized formats for media
Best Practices
- Keep it under 50,000 URLs: Use sitemap index for larger sites
- Update regularly: Regenerate when content changes
- Use absolute URLs: Include full URLs with protocol
- Submit to search engines: Use Google Search Console and Bing
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-generate": {
"url": "https://api.tinyfn.io/mcp/generate/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all generator tools available via MCP in our Generator MCP Tools for AI Agents guide.
Try the Sitemap Generator API
Get your free API key and start creating sitemaps in seconds.
Get Free API Key