<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mian po</title>
    <description>The latest articles on DEV Community by mian po (@mian_po_0ae30e900c601c8f5).</description>
    <link>https://dev.to/mian_po_0ae30e900c601c8f5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4030024%2Fe18db574-e8e1-4e67-b4f2-012f6bc9289e.jpg</url>
      <title>DEV Community: mian po</title>
      <link>https://dev.to/mian_po_0ae30e900c601c8f5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mian_po_0ae30e900c601c8f5"/>
    <language>en</language>
    <item>
      <title>Engineering Reliable Cursor Workflows for Public RedNote Data</title>
      <dc:creator>mian po</dc:creator>
      <pubDate>Wed, 15 Jul 2026 09:12:39 +0000</pubDate>
      <link>https://dev.to/mian_po_0ae30e900c601c8f5/engineering-reliable-cursor-workflows-for-public-rednote-data-533p</link>
      <guid>https://dev.to/mian_po_0ae30e900c601c8f5/engineering-reliable-cursor-workflows-for-public-rednote-data-533p</guid>
      <description>&lt;p&gt;Social-data integrations often fail in boring places: a copied page token expires, a cursor is reused with the wrong resource, a timeout is mistaken for an empty page, or a missing metric is silently converted into zero.&lt;/p&gt;

&lt;p&gt;I built the public examples for &lt;a href="https://rapidapi.com/pomiandaitumm/api/xhs-data-api" rel="noopener noreferrer"&gt;XHS Data API&lt;/a&gt; around those failure modes rather than around the happy path alone. The API exposes normalized public Xiaohongshu (RedNote) note details, top-level comments, author profiles, published-note pages, media inventories, and sequential batches.&lt;/p&gt;

&lt;p&gt;The complete Python and Node.js examples are available from the &lt;a href="https://xhs-data-api.pages.dev/" rel="noopener noreferrer"&gt;developer website&lt;/a&gt; as a &lt;a href="https://xhs-data-api.pages.dev/downloads/xhs-data-api-examples-v1.0.0.zip" rel="noopener noreferrer"&gt;versioned download&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start With A Complete Public URL
&lt;/h2&gt;

&lt;p&gt;Detail and comment requests use the complete public note URL, including its current &lt;code&gt;xsec_token&lt;/code&gt;. Keep the URL and RapidAPI key in server-side environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;X_RAPIDAPI_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your_rapidapi_key"&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;XHS_NOTE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"complete_current_public_note_url"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First validate the URL locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_note_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;XHS_NOTE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;detail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;detail_from_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;XHS_NOTE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;note_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;note&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parser does not fetch upstream data. This separates malformed-input errors from upstream availability errors before the expensive step begins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat Cursor State As A Contract
&lt;/h2&gt;

&lt;p&gt;The first comment request has no cursor. Every later request must use the exact &lt;code&gt;next_cursor&lt;/code&gt; returned by the previous page and keep the same note URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cursor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;comments_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;note_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;items&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;comment_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;comment_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;has_more&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="n"&gt;cursor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;next_cursor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client repository also deduplicates IDs defensively. A cursor is short-lived and resource-bound; editing it or moving it to another note is a client error.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Timeout Is Not An Empty Page
&lt;/h2&gt;

&lt;p&gt;When an upstream page cannot finish within the service budget, the API returns a structured error instead of &lt;code&gt;200&lt;/code&gt; with an empty list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"msg"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Comments did not load"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"error_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"REQUEST_TIMEOUT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"request_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"support-id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"retry_after"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait for &lt;code&gt;Retry-After&lt;/code&gt;, then retry the identical URL and cursor. Do not advance the chain. Long cooldowns are intentionally not hidden behind aggressive automatic retries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve Unknown Values
&lt;/h2&gt;

&lt;p&gt;Public profile cards and note summaries do not always contain full engagement or media fields. The normalized contract returns &lt;code&gt;null&lt;/code&gt; when the source did not supply a value. That is different from numeric zero and boolean false.&lt;/p&gt;

&lt;p&gt;This detail matters in dashboards. Converting unknown likes to zero changes averages, rankings, and trend lines. The user-note endpoints expose content coverage so an application can choose a lightweight summary page or request a small detail-enriched page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Support IDs, Not Secrets
&lt;/h2&gt;

&lt;p&gt;Every response includes &lt;code&gt;data.request_id&lt;/code&gt;. Log that ID with the endpoint and HTTP status. Do not log RapidAPI keys, cookies, browser state, or complete signed URLs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try The Examples
&lt;/h2&gt;

&lt;p&gt;The repository includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a reusable Python client with structured errors and bounded retries;&lt;/li&gt;
&lt;li&gt;Node.js 20 examples using built-in &lt;code&gt;fetch&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;duplicate-safe comment and user-note pagination;&lt;/li&gt;
&lt;li&gt;asynchronous batch submission and polling;&lt;/li&gt;
&lt;li&gt;troubleshooting guidance for &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt;, and &lt;code&gt;503&lt;/code&gt; responses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start with the &lt;a href="https://xhs-data-api.pages.dev/guides/" rel="noopener noreferrer"&gt;developer guides&lt;/a&gt; or download the &lt;a href="https://xhs-data-api.pages.dev/downloads/xhs-data-api-examples-v1.0.0.zip" rel="noopener noreferrer"&gt;client examples&lt;/a&gt;. The current public API focuses on stable read workflows and does not advertise note search or child-comment replies.&lt;/p&gt;

&lt;p&gt;XHS Data API is independent and is not affiliated with or endorsed by Xiaohongshu/RedNote. Use public data lawfully and follow applicable law, third-party rights, and source-platform rules.&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
