Back to Blog

RedNote (Xiaohongshu) API Quickstart with Java

Rnote API Team · · 38 views · 中文
Xiaohongshu Data API Tutorial Java

This tutorial connects you to the RedNote (Xiaohongshu) data API with Java. You build no crawler — the Rnote API handles collection infrastructure, and you just send a GET request with an X-API-Key header using Java 11+'s built-in HttpClient. You can also follow the Python, Node.js, Go, and PHP versions.

Step 1: Sign up and get an API key

Go to the sign-up page, create an account, verify your email, and get free credits plus your API key.

Step 2: Make your first request

Standard library only (java.net.http.HttpClient, Java 11+) — no third-party dependencies:

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class Quickstart {
    public static void main(String[] args) throws Exception {
        String keyword = URLEncoder.encode("camping gear", StandardCharsets.UTF_8);
        String url = "https://rnote.dev/api/v2/crawler/search/notes"
                   + "?keyword=" + keyword + "&page=1";

        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("X-API-Key", "YOUR_API_KEY")
                .GET()
                .build();

        HttpResponse<String> resp = HttpClient.newHttpClient()
                .send(req, HttpResponse.BodyHandlers.ofString());

        System.out.println(resp.statusCode());
        System.out.println(resp.body());
    }
}

Once that works, swap the endpoint for note/image (image-note details), user/info (creator info), and more — see the API docs for parameters.

Step 3: Wrap a call with retries

import java.net.URI;
import java.net.http.*;
import java.util.Map;
import java.util.StringJoiner;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

static String call(String path, Map<String, String> params, int retries) throws Exception {
    StringJoiner q = new StringJoiner("&");
    for (var e : params.entrySet()) {
        q.add(e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8));
    }
    String url = "https://rnote.dev/api/v2/crawler/" + path + "?" + q;
    HttpClient client = HttpClient.newHttpClient();

    for (int i = 0; i < retries; i++) {
        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("X-API-Key", "YOUR_API_KEY")
                .GET().build();
        HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
        if (resp.statusCode() == 200) return resp.body();
        Thread.sleep((long) Math.pow(2, i) * 1000); // exponential backoff
    }
    throw new RuntimeException("request failed after retries");
}

Only successful (HTTP 2xx) requests are billed, so retries on failures cost nothing — add retry logic with confidence.

Pricing & credits

Billed per request, no monthly fee, no minimum; free credits on sign-up. See top-up options and current offers on the pricing page.

Next steps

Sign up free and send your first request with Java now.