jackwener/OpenCLI · error
API failed
Error message
API failed
What it means
The nowcoder referral command evaluates an in-page script that fetches gw-c.nowcoder.com/api/sparta/home/tab/content (tabId=861). If d.success is falsy it throws Error(d.msg || 'API failed'); 'API failed' is the fallback when the API gives no message. This signals the tab-content endpoint refused the request.
Source
Thrown at clis/nowcoder/referral.js:21
cli({
site: 'nowcoder',
name: 'referral',
access: 'read',
description: 'Internal referral posts',
domain: 'www.nowcoder.com',
args: [
{ name: 'page', type: 'int', default: 1, help: 'Page number' },
{ name: 'limit', type: 'int', default: 15, help: 'Number of items' },
],
columns: ['rank', 'title', 'author', 'school', 'likes', 'comments', 'views', 'id'],
pipeline: [
{ navigate: 'https://www.nowcoder.com' },
{ evaluate: `(async () => {
const page = \${{ args.page }};
const limit = \${{ args.limit }};
const r = await fetch('https://gw-c.nowcoder.com/api/sparta/home/tab/content?tabId=861&categoryType=1&pageNo=' + page + '&pageSize=' + limit, {credentials: 'include'});
const d = await r.json();
if (!d.success) throw new Error(d.msg || 'API failed');
return (d.data?.records || []).map((item, i) => {
const content = item.contentData || item.momentData || {};
return {
rank: i + 1,
title: content.title || '',
author: item.userBrief?.nickname || '',
school: item.userBrief?.educationInfo || '',
likes: item.frequencyData?.likeCnt || 0,
comments: item.frequencyData?.commentCnt || 0,
views: item.frequencyData?.viewCnt || 0,
id: item.momentData?.uuid || item.contentData?.uuid || item.contentId || '',
};
});
})()
` },
{ filter: 'item.title' },
{ limit: '${{ args.limit }}' },
],View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to nowcoder.com in the driving browser session so credentials are included
- Verify page/limit arguments are in a sane range (start at page 1)
- Retry later in case of rate limiting
- Check the endpoint/tabId still exists and update clis/nowcoder/referral.js if Nowcoder changed it
Example fix
// before
if (!d.success) throw new Error(d.msg || 'API failed');
// after
if (!d.success) throw new Error('referral tab-content error: ' + (d.msg || JSON.stringify(d).slice(0,120))); Defensive patterns
Strategy: retry
Validate before calling
const pageNo = Math.max(1, Number(page) || 1); const pageSize = Math.min(50, Math.max(1, Number(limit) || 10));
Type guard
function tabContentOk(d){ return !!d && typeof d === 'object' && d.success === true && Array.isArray(d.data?.records); } Try / catch
try { await run(['nowcoder', 'referral']); }
catch (e) {
if (String(e.message).includes('API failed')) { await sleep(3000); /* retry once, or check login */ }
else throw e;
} Prevention
- Keep the automated browser logged in to nowcoder.com
- Start pagination at page 1 and stop when records come back empty
- Verify tabId 861 still exists after Nowcoder UI updates
- Distinguish HTTP errors from business errors by checking r.ok first
When it happens
Trigger: Running `nowcoder referral` when the tab/content endpoint returns success:false with no msg — invalid pageNo/pageSize, missing session despite credentials:'include', endpoint removed, or throttling.
Common situations: Expired login session on nowcoder.com in the automated browser; Nowcoder changing tabId 861 (referral tab) semantics or removing it; requesting pages beyond available content.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/66522215eeb1905b.
Report an issue: GitHub.