Submit URLs to Baidu via API

May 2, 2025 · 2 min read · 220 Words · -Views -Comments · Programming
Baidu SEO 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

I wanted Baidu to index more of my blog posts, so I set up API submissions. Here’s the process.

Get the API Token

Open Baidu Search Console, select your site, then Regular Inclusion → Resource Submission → API Submission. The token displayed there authorizes submissions—keep it secret.

https://static.1991421.cn/2025/2025-05-02-223610.jpeg

Submit URLs

Example Node.js script for my Hugo blog; any language works.

const SITEMAP_FILE = path.join(__dirname, '../public/sitemap.xml'); // sitemap path
const BAIDU_API_URL = `http://data.zz.baidu.com/urls?site=1991421.cn&token=${process.env.BAIDU_ZZ_TOKEN}`; // Baidu submission endpoint
const MAX_URLS = 5; // max URLs per request

async function submitToBaidu(urls) {
  try {
    console.log('Submitting URLs', urls);
    const response = await fetch(BAIDU_API_URL, {
      method: 'POST',
      headers: {
        'Content-Type': 'text/plain'
      },
      body: urls.join('\n') // newline-delimited list
    });

    if (!response.ok) {
      throw new Error(`HTTP error: ${response.status}`);
    }

    const data = await response.json();
    console.log('Submit success:', data);
  } catch (error) {
    console.error('Submit failed:', error.message);
  }
}

My Workflow

I run this script in GitHub Actions. Each build generates sitemap.xml; the action grabs the newest N URLs and posts them to Baidu.

Common Questions

Daily Quota

  • 10 URLs per day.
  • Exceeding the quota returns HTTP 400.

Common 400 Errors

  1. Quota exceeded
  2. Invalid token
  3. Wrong site parameter (omit the protocol, e.g. site=1991421.cn)

Closing Thoughts

Baidu isn’t my favorite, but it’s still worth submitting URLs for mainland readers. If you know a better method, leave a comment.

Further Reading

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover