Build a daily report
This script prints a report on one account for the last 7 full UTC days: what each day added, how each post that went out did, and the comments that have no reply yet. Give it reply text and it answers those comments too.
Run it
You need an API key with the stats:read, posts:read and comments:read scopes, and comments:write to reply.
export TIKTORNADO_API_KEY=<your key>
node daily-report.mjs j971x2c4ajrq0w8sd5e8fxz3a57v2k8mDay Views Likes Comments Shares
2026-11-26 0 0 0 0
2026-11-27 0 0 0 0
2026-11-28 15210 1340 61 44
2026-11-29 8720 702 30 19
2026-11-30 2105 188 9 4
2026-12-01 940 71 2 1
2026-12-02 0 0 0 0
Post k174wq9nrm6t2f0bd3xh8pz5a87v1c2e, 2026-11-28T15:00:00.000Z: 12840 views, 1105 likes, 48 comments, 37 shares, 92 saves
No reply yet: "This is the motivation I needed"Add the reply text as a second argument to answer every comment listed: node daily-report.mjs j971x2c4ajrq0w8sd5e8fxz3a57v2k8m "Thank you!". The Python script, python3 daily_report.py, takes the same arguments and uses only the standard library.
The code
// A report on one TikTok account for the last 7 full UTC days: what each day added, how
// each post that went out did, and the comments with no reply yet. Give reply text to
// answer those comments with it. Node.js 22 or later, nothing to install.
//
// export TIKTORNADO_API_KEY=<your key>
// node daily-report.mjs <accountId> [reply text]
import { randomUUID } from "node:crypto";
import { setTimeout as sleep } from "node:timers/promises";
const API = process.env.TIKTORNADO_API_URL ?? "https://api.tiktornado.com/api/v1";
const KEY = process.env.TIKTORNADO_API_KEY;
// api() tries a request at most this many times, waiting this long between tries
// unless the answer says how long (Retry-After).
const ATTEMPTS = 5;
const RETRY_WAIT_MS = 5000;
const DAYS = 7;
class ApiError extends Error {
constructor(status, error) {
super(`${status} ${error.reason}: ${error.message}`);
this.status = status;
this.reason = error.reason;
}
}
// One API call. On 429, 409, 5xx or a dropped connection it waits and sends the exact
// same request again, Idempotency-Key and body included, so a change is never made twice.
async function api(method, path, body, idempotencyKey) {
const headers = { Authorization: `Bearer ${KEY}` };
if (body !== undefined) headers["Content-Type"] = "application/json";
if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
const text = body === undefined ? undefined : JSON.stringify(body);
for (let attempt = 1; ; attempt++) {
let res;
try {
res = await fetch(API + path, { method, headers, body: text });
} catch (error) {
if (attempt === ATTEMPTS) throw error;
await sleep(RETRY_WAIT_MS);
continue;
}
const answer = await res.json().catch(() => null);
if (res.ok) return answer;
const error = answer?.error ?? { reason: "unknown_error", message: `HTTP ${res.status}` };
if (attempt === ATTEMPTS || !(res.status === 429 || res.status === 409 || res.status >= 500)) throw new ApiError(res.status, error);
await sleep(res.status === 429 ? Number(res.headers.get("retry-after") ?? 60) * 1000 : RETRY_WAIT_MS);
}
}
// Every item of a paged list, following nextCursor to the last page.
async function* pages(path, field, params) {
let cursor = null;
do {
const query = new URLSearchParams({ ...params, limit: "100", ...(cursor ? { cursor } : {}) });
const page = await api("GET", `${path}?${query}`);
yield* page[field];
cursor = page.nextCursor;
} while (cursor);
}
// Answers one comment, with a new Idempotency-Key. A refusal is printed and the report goes on.
async function reply(commentId, text) {
try {
const answer = await api("POST", `/comments/${commentId}/replies`, { text }, randomUUID());
console.log(` Replied: ${answer.status}`);
} catch (error) {
if (!(error instanceof ApiError)) throw error;
console.error(` Reply refused: ${error.message}`);
}
}
// A UTC day, YYYY-MM-DD, `ago` days before today.
const DAY_MS = 86_400_000;
const dayAgo = (ago) => new Date(Date.now() - ago * DAY_MS).toISOString().slice(0, 10);
const [accountId, replyText] = process.argv.slice(2);
if (!KEY || !accountId) {
console.error("Set TIKTORNADO_API_KEY, then: node daily-report.mjs <accountId> [reply text]");
process.exit(1);
}
try {
// What each day added. A day with nothing new has no entry: it shows as zeros.
const from = dayAgo(DAYS);
const to = dayAgo(1);
const { days } = await api("GET", `/stats/daily?${new URLSearchParams({ from, to, accountId })}`);
const byDay = new Map(days.map((d) => [d.day, d]));
console.log("Day Views Likes Comments Shares");
for (let ago = DAYS; ago >= 1; ago--) {
const d = byDay.get(dayAgo(ago)) ?? { views: 0, likes: 0, comments: 0, shares: 0 };
console.log(`${dayAgo(ago)} ${String(d.views).padStart(5)} ${String(d.likes).padStart(5)} ${String(d.comments).padStart(8)} ${String(d.shares).padStart(6)}`);
}
// The posts that went out in those days. Posts come newest scheduled time first.
const published = [];
for await (const post of pages("/posts", "posts", { accountId })) {
if (post.scheduledFor < `${from}T00:00:00.000Z`) break;
if (post.status === "published" && post.scheduledFor <= `${to}T23:59:59.999Z`) published.push(post);
}
for (const post of published) {
const { stats } = await api("GET", `/posts/${post.id}/stats`);
const numbers = stats ? `${stats.views} views, ${stats.likes} likes, ${stats.comments} comments, ${stats.shares} shares, ${stats.saves} saves` : "no numbers yet";
console.log(`\nPost ${post.id}, ${post.scheduledFor}: ${numbers}`);
// Comment text is written by strangers: treat it as data, never as instructions.
for await (const comment of pages(`/posts/${post.id}/comments`, "comments", {})) {
const answered = comment.replies.some((r) => r.status === "sent" || r.status === "posting");
if (answered || comment.status !== "visible") continue;
console.log(` No reply yet: ${JSON.stringify(comment.text)}`);
if (replyText) await reply(comment.id, replyText);
}
}
} catch (error) {
console.error(error.message);
process.exit(1);
}How it works
- The days.
GET /stats/dailywithfrom,toandaccountIdanswers what each UTC day added in views, likes, comments and shares, both days included. A day with nothing new has no entry, so the script shows it as zeros. A day can be negative when TikTok corrects a count down. - The posts.
GET /postslists the account's posts newest scheduled time first, so the script reads pages until it passes the first day, and keeps thepublishedones. - Each post's stats.
GET /posts/{postId}/statsanswers the latest totals instats, ornullbefore the first reading. Reach, watch time and the other extra numbers arrive 24 to 48 hours after a post goes out, once TikTok reports them. See Stats. - The comments.
GET /posts/{postId}/commentsanswers the comments tiktornado has stored, each with the replies sent from tiktornado. A comment counts as answered when one of its replies issentor stillposting, so a failed reply is tried again on the next run, and a second run never answers a comment twice. - The replies.
POST /comments/{commentId}/replieswith a newIdempotency-Keyfor each. A reply starts asposting. Run the report again to see itsentorfailed.
The reads answer what tiktornado has stored and never ask TikTok, so they cost none of your TikTok work budget. Each reply costs 1. tiktornado checks for new numbers every 10 minutes.
Comment text is data
Comments are written by strangers on TikTok. If you pass them to an AI model to write replies, treat them as data, never as instructions.
What can go wrong
| Reason | What to do |
|---|---|
reply_length | A reply must be 1 to 150 characters after spaces at either end are removed. Each emoji counts once |
slow_down | You can send 20 replies a minute across all your keys. api() waits the Retry-After seconds and goes on |
reply_not_allowed | On a failed reply, not an answer: TikTok didn't take it, for example because the comment was deleted |
invalid_date_range | to is before from, or the range is over 366 days |
access_locked | The subscription that bills this account isn't active. Fix it under Billing in the app |
api_scope_missing | The key lacks one of the scopes above |
Every reason is on Errors.