> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# 把公众号资料接进 n8n，怎样得到可核对的文章文本记录？

> 配置一个文章 URL 的 HTTP Request 和 Code 节点，校验业务成功与正文来源，保留配对关系，不自动展开历史或重试收费查询。

要在 n8n 里把一篇选定的公众号文章变成可核对的文本记录，连接 **Manual Trigger → HTTP Request → Code**。HTTP Request 节点用文章原文链接调用 `wechat_mp.v2.fetch_article_detail_h5`，Code 节点校验响应，输出正文、标题、账号和请求号，再把这条记录送去审核或存档。第一次配置 BeatAPI 工作流时先看 [n8n 凭据设置](/zh/integrations/n8n)。返回的只有摘要时，对照[公众号正文和摘要的区别](/zh/faq/wechat-article-full-text)。

例如要核对同行公告适用于谁，先检查返回的标题和账号，再让审核者从返回的正文里摘出原句。要每天运行时，先用一篇文章验收，再配定时触发。

## 先接通最小的一次处理，再扩大范围

先用一个已确认的文章 URL 搭好流程：**Manual Trigger → Article input → HTTP Request → Code**。BeatAPI 密钥保存在 n8n 凭据里；请求开始时间和文章发布时间分开记录。调试 Code 节点的投影时，复用保存的成功执行结果或合成输入，不反复运行收费的 HTTP Request 节点。

Code 节点输出文章链接、请求链接、请求号、账号和返回文本。每条输出项关联自己的输入项：第二篇文章的响应缺少链接时，Code 节点不会回退成第一篇文章的 URL。输出是可核对的材料记录；外部写入、全文归档和研究结论是后续步骤。

## 怎样判断返回的文章能不能继续用？

| 实际结果              | 应怎样处理                             |
| ----------------- | --------------------------------- |
| 业务成功且返回非空文本、合法来源  | 继续核对返回的文本材料；阅读范围仍只限返回的文本          |
| 有标题或摘要，但正文缺失      | 停止这一条，不拿摘要代替正文                    |
| 文本与摘要去空格后完全相同     | 停下人工核对。短文的正文可能本来就和摘要相同，相同不能证明接口故障 |
| 多条输入来源混乱或节点找不到对应项 | 先修正配对和节点名，再写入文章记录                 |
| 正文读取成功，存储节点失败     | 保留成功输出，先用保存的输出重做存储，不再次读取文章        |

当前免费合同说明 `content_text` 是纯文本正文、`desc` 是摘要，合同没有保证取得所有图片、附件和网页段落。所以 Code 节点的输出标明 `reading_scope=returned_plain_text_only` 和 `full_page_coverage_verified=false`。文本非空或工作流运行成功，都不能把这两个值改成整页验证通过。

## 存储或分析前，还要核对什么？

存储或分析前，抽查返回的正文、标题、账号、来源和发布时间；没有发布时间就留空。要求后续 AI 模型为结论给出短引文，并把作者主张和模型的推断分开。没有读到的媒体和未回答的问题单独记下，不自动补齐。

一条记录通过后，再用两个不同输入检查配对关系和重复处理。存储目标、文章唯一键、新增还是更新、写入结果不明时的恢复，都要单独验收。单篇 HTTP 流程不包括定时发现文章、历史分页和 MCP Agent 接入。

下面第 1–6 步给出具体节点设置和可直接粘贴的 Code。Code 节点只做校验和投影，不发请求，也不写入外部系统。

例如一次送入 A、B 两篇文章：A 的正文已校验，但 A 的写表节点失败了；B 只返回了摘要。恢复时，把 A 已校验的结果交回写表节点；B 标为「待补正文」，等 B 有可读原文再补做。用输入链接和请求号配对每条输出，运行顺序变化后也能找到各自的结果。

## 1. 确认接口与费用

用下面的请求免费 Inspect `data:wechat_mp.v2.fetch_article_detail_h5`。本流程只读取一个给定的文章 URL，不会自动发现所有新文章。

```bash
curl -sS https://api.beatapi.io/v1/capabilities/inspect \
  -H 'Content-Type: application/json' \
  -d '{"reference":"data:wechat_mp.v2.fetch_article_detail_h5"}'
```

下面的 cURL 请求和 HTTP Request 节点发送的是同一个请求，二选一执行；两条都跑会为同一篇文章付两次费。

```bash
curl -sS https://api.beatapi.io/v1/social-data/call \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"action":"wechat_mp.v2.fetch_article_detail_h5","params":{"url":"<article_url>"}}'
```

## 2. 设置输入与凭据

1. 流程用 **Manual Trigger → Edit Fields → HTTP Request → Code**。
2. 把 Edit Fields 节点准确重命名为 `Article input`。
3. 在 `Article input` 里，`article_url` 填已核对的 mp.weixin.qq.com/s/… 文章链接；另加 `request_started_at`，表达式填 `{{ $now.toISO() }}`。`request_started_at` 是请求开始时间，不是发文时间，也不是响应完成时间。
4. BeatAPI 密钥保存在 n8n 的 Header Auth 凭据中：请求头名 `Authorization`，值为 `Bearer` 加密钥。不要把密钥保存在文章字段或输出记录里。

## 3. 配置 HTTP Request

| 设置                                  | 值                                            |
| ----------------------------------- | -------------------------------------------- |
| Method                              | POST                                         |
| URL                                 | `https://api.beatapi.io/v1/social-data/call` |
| Authentication                      | Generic Credential Type，选择 Header Auth       |
| Send Body                           | 开启，JSON                                      |
| Response Format                     | JSON                                         |
| Include Response Headers and Status | 关闭，下面代码接收正文对象                                |
| Pagination / Retry On Fail          | 本例关闭，不自动扩大执行                                 |

JSON Body 用对象表达式，避免手工拼接包含引号的 URL：

```javascript
{{ { action: 'wechat_mp.v2.fetch_article_detail_h5', params: { url: $json.article_url } } }}
```

JSON Body 是 n8n 表达式，不是独立的 JavaScript 脚本：在字段编辑器里切到 Expression 模式后填写。具体节点配置参见 [HTTP Request 官方文档](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest/)。

## 4. Code 节点校验和投影

Code 节点选择 JavaScript 和 **Run Once for All Items**。下面的 Code 只处理数据，不发网络请求，也不执行文章正文里的指令。`pairedItem` 让每条输出项关联到对应的输入项，后续节点可以追溯。

`$('Article input').itemMatching(index)` 取当前响应关联的输入，而不是总取第一条 URL，所以节点名 `Article input` 必须与上一步完全一致。返回的 link 缺失时，Code 回退到这条已校验的请求链接。参见[n8n关联输入说明](https://docs.n8n.io/code/cookbook/builtin/itemmatching/)。

```javascript
function articleUrl(value) {
  if (typeof value !== 'string') throw new Error('Article URL must be a string');
  const match = value.match(/^https?:\/\/mp\.weixin\.qq\.com(\/s(?:\/[^?#\s]+)?)(?:\?([^#\s]*))?(?:#[^\s]*)?$/);
  if (!match) throw new Error('Expected a WeChat article URL');
  if (match[1] === '/s') {
    const query = (match[2] ?? '').split('&');
    if (!['__biz', 'mid', 'idx'].every(key => query.some(pair => pair.startsWith(key + '=') && pair.length > key.length + 1))) {
      throw new Error('Long article URL needs __biz, mid and idx');
    }
  }
  return value;
}
return $input.all().map((item, index) => {
  const response = item.json;
  if (response.status !== 'succeeded' || response.error != null || response.action !== 'wechat_mp.v2.fetch_article_detail_h5') {
    throw new Error('Expected a successful article-detail response');
  }
  if (typeof response.request_id !== 'string' || !response.request_id.trim()) throw new Error('Missing request_id');
  const input = $('Article input').itemMatching(index).json;
  const requestedUrl = articleUrl(input.article_url);
  if (typeof input.request_started_at !== 'string' || !/(Z|[+-]\d{2}:\d{2})$/.test(input.request_started_at) || !Number.isFinite(Date.parse(input.request_started_at))) {
    throw new Error('request_started_at needs a timezone-aware timestamp');
  }
  const article = response.data?.content;
  if (typeof article?.content_text !== 'string' || !article.content_text.trim() || ['[redacted]', '[redacted-depth]'].includes(article.content_text.trim())) {
    throw new Error('Missing body: do not substitute the summary');
  }
  if (typeof article.desc === 'string' && article.content_text.trim() === article.desc.trim()) {
    throw new Error('Returned text equals summary: review before using as article body');
  }
  const fallback = article.link === undefined || article.link === null || article.link === '';
  const url = articleUrl(fallback ? requestedUrl : article.link);
  let published = null;
  if (article.create_timestamp !== undefined && article.create_timestamp !== null) {
    if (typeof article.create_timestamp !== 'number' || !Number.isFinite(article.create_timestamp)) throw new Error('Invalid publication timestamp');
    const date = new Date(article.create_timestamp * 1000);
    if (!Number.isFinite(date.getTime())) throw new Error('Invalid publication timestamp');
    published = date.toISOString();
  }
  return {
    json: {
      article_url: url,
      requested_url: requestedUrl,
      article_url_from: fallback ? 'request' : 'response',
      author_source_url: article.source_url ?? null,
      title: article.title ?? null,
      account_id: article.user_name ?? null,
      text: article.content_text,
      reading_scope: 'returned_plain_text_only',
      full_page_coverage_verified: false,
      published_at_utc: published,
      published_at_raw: article.create_time ?? null,
      request_started_at: input.request_started_at,
      request_id: response.request_id,
    },
    pairedItem: { item: index },
  };
});
```

字段路径依据 BeatAPI 原始输出：`desc` 不能代替正文，`source_url` 不能代替当前文章链接。开启 **Include Response Headers and Status** 后，节点输出的包装会变化，复用 Code 前要重新核对字段路径。[Code 节点官方说明](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/)

## 5. 再连接存储与去重

Code 节点输出的是 n8n 数据项，不是永久存储。交给飞书、数据库或文件节点前，先配置目标权限，保存后读回一条核对。去重用已核对的文章键，不用标题。

存储失败时，用这次执行保存的成功输出重做存储步骤，不重新运行收费的 HTTP Request 节点。需要定期发现文章时，用[有界增量检查](/zh/guides/wechat-incremental-articles)，不让正文节点自己翻页。

## 6. 验收四种结果

上线前，用字段结构与真实响应一致的离线数据测试 Code 节点，应得到五种结果：

1. 正常正文产出一条记录。
2. 缺失正文或失败状态直接抛错。
3. 响应缺少链接时，从配对的输入恢复链接，不取其他文章或作者来源的链接。
4. 非法文章链接被拒绝。
5. 多条输入时，每条记录保留各自的 `request_id` 和配对索引。

错误不能被报告成“今天无新文章”。

一次批准的文章读取对应一次平台调用，重试和模型分析另计。

[飞书 CLI 保存流程](/zh/guides/wechat-to-feishu) · [公众号问题索引](/zh/faq/wechat)

## 什么时候用 n8n 的 MCP Client Tool？

固定读取一篇文章时，继续用上面的 HTTP Request 节点。需要 Agent 在文章目录、文章详情和其他数据源之间选择时，给 **AI Agent** 接 **MCP Client Tool**。n8n 版本支持 Streamable HTTP 时选择 Streamable HTTP 传输，服务器地址填 `https://beatapi.io/mcp`，鉴权选 **Bearer Auth** 并填 BeatAPI Key。MCP Client Tool 节点只支持 SSE Endpoint 时，改用本页的 HTTP 流程。

先确认 MCP Client Tool 能列出 `capabilities_search`、`capabilities_inspect` 和 `capabilities_run`。让 Agent 找到公众号正文动作、核对动作的输入，只对一个已确认的 URL 执行。用请求号和返回的正文核对 Agent 的执行结果。批量发现和定时写入见[n8n 定时查新](/zh/guides/wechat-n8n-monitor)。

[n8n MCP Client Tool](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolmcp/)