{
  "id": "PITBb7KbXahwGl06",
  "name": "Get Xiaohongshu note comments with JustOneAPI",
  "tags": [],
  "nodes": [
    {
      "id": "a07fb06a-b555-43b7-98cd-99a1725d494c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4464,
        1168
      ],
      "parameters": {
        "width": 528,
        "height": 496,
        "content": "## Get Xiaohongshu note comments with JustOneAPI\n\n### How it works\n\n1. The workflow is triggered manually.\n2. It prepares API and comment inputs for the request.\n3. It fetches Xiaohongshu note comments via HTTP GET request.\n4. It outputs the raw comment response and builds a comment list.\n5. It outputs the final comment list.\n\n### Setup steps\n\n- - [ ] Configure the Manual Execution Trigger node to start the workflow.\n- [ ] Set the required fields in the Prepare API and Comment Inputs node for the API request.\n- [ ] Ensure the HTTP request node Fetch Xiaohongshu Note Comments has the correct endpoint URL and parameters.\n\n### Customization\n\nYou can customize the API endpoint URL and parameters in the Prepare API and Comment Inputs node to fetch comments from different Xiaohongshu notes."
      },
      "typeVersion": 1
    },
    {
      "id": "be22b7f1-242f-49ae-84b8-b8063bc64cfb",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5008,
        1168
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 112,
        "content": "## Workflow Trigger\n\nManually triggers the workflow to start execution."
      },
      "typeVersion": 1
    },
    {
      "id": "b5889474-09b7-4116-b0ad-2255c10eeb0e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5280,
        1168
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 112,
        "content": "## Prepare API Request\n\nSets up the necessary inputs and configurations for the API request to fetch Xiaohongshu note comments."
      },
      "typeVersion": 1
    },
    {
      "id": "e31e95fd-da26-4a74-bbcc-687b20955fd4",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5600,
        1168
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 128,
        "content": "## Fetch Comments\n\nMakes an HTTP GET request to the Xiaohongshu API to retrieve note comments."
      },
      "typeVersion": 1
    },
    {
      "id": "bbf77102-a624-4fa6-89ae-6fb1bcf82ecf",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5920,
        1168
      ],
      "parameters": {
        "color": 7,
        "height": 176,
        "content": "## Output Raw Response\n\nOutputs the raw response received from the Xiaohongshu API for debugging or further processing."
      },
      "typeVersion": 1
    },
    {
      "id": "120aac63-b7b1-4963-9248-becaa656a8b0",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6240,
        1168
      ],
      "parameters": {
        "color": 7,
        "height": 144,
        "content": "## Build Comment List\n\nProcesses the raw response to build a structured list of comments using custom code."
      },
      "typeVersion": 1
    },
    {
      "id": "d2fd8eb2-3670-4ac8-9ab6-70de9ac7ca16",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6752,
        1168
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 144,
        "content": "## Output Final Comment List\n\nOutputs the final structured list of comments after processing."
      },
      "typeVersion": 1
    },
    {
      "id": "85902a86-5db0-4657-b493-a825487fe65f",
      "name": "Start Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        5072,
        1360
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d2fce207-8f1d-4682-91e6-2d6b1de6b311",
      "name": "Set API and Comment Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        5344,
        1360
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"baseUrl\": \"https://api.justoneapi.com\",\n  \"token\": \"YOUR_JUSTONEAPI_TOKEN\",\n  \"noteId\": \"YOUR_NOTE_ID\",\n  \"maxComments\": 20\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "a17056b4-cce5-4ed3-a065-0791d96aea3e",
      "name": "Fetch Xiaohongshu Comments via API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5648,
        1360
      ],
      "parameters": {
        "url": "={{$json.baseUrl + '/api/xiaohongshu/get-note-comment/v4'}}",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "token",
              "value": "={{$json.token}}"
            },
            {
              "name": "noteId",
              "value": "={{$json.noteId}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ad75bdfc-f0d6-4818-82cc-4ec3195c5a70",
      "name": "Output Raw API Response",
      "type": "n8n-nodes-base.set",
      "position": [
        5968,
        1584
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "273c1854-a8df-439e-aeed-d792fcc74983",
      "name": "Parse and Build Comment List",
      "type": "n8n-nodes-base.code",
      "position": [
        6288,
        1360
      ],
      "parameters": {
        "jsCode": "const rows = $input.all();\n\nfunction firstDefined(...values) {\n  for (const value of values) {\n    if (value !== undefined && value !== null && value !== '') return value;\n  }\n  return '';\n}\n\nfunction pickCommentList(payload) {\n  const candidates = [\n    payload?.data?.comments,\n    payload?.data?.comment_list,\n    payload?.data?.list,\n    payload?.data?.items,\n    payload?.comments,\n    payload?.comment_list,\n    payload?.list,\n    payload?.items,\n  ];\n\n  for (const candidate of candidates) {\n    if (Array.isArray(candidate)) return candidate;\n  }\n\n  if (Array.isArray(payload?.data?.data)) return payload.data.data;\n  if (Array.isArray(payload?.data?.comments?.items)) return payload.data.comments.items;\n\n  return [];\n}\n\nconst results = [];\n\nfor (const item of rows) {\n  const payload = item.json || {};\n  const cfg = $('Set API and Comment Parameters').first().json;\n  const data = payload.data || {};\n  const maxComments = Math.max(1, Number(cfg.maxComments || 20));\n  const comments = pickCommentList(payload).slice(0, maxComments);\n\n  const normalized = comments.map((comment, index) => {\n    const user = comment.user || comment.author || comment.comment_user_info || {};\n\n    return {\n      index: index + 1,\n      commentId: firstDefined(comment.id, comment.comment_id, comment.commentId),\n      noteId: firstDefined(comment.note_id, comment.noteId, cfg.noteId),\n      content: firstDefined(comment.content, comment.text, comment.desc, comment.comment),\n      likeCount: Number(firstDefined(comment.like_count, comment.likes, comment.liked_count, 0) || 0),\n      replyCount: Number(firstDefined(comment.sub_comment_count, comment.reply_count, comment.replyCount, 0) || 0),\n      createTime: firstDefined(comment.create_time, comment.time, comment.publish_time),\n      ipLocation: firstDefined(comment.ip_location, comment.location),\n      status: firstDefined(comment.status, 0),\n      hidden: Boolean(comment.hidden ?? false),\n      liked: Boolean(comment.liked ?? false),\n      collected: Boolean(comment.collected ?? false),\n      showType: firstDefined(comment.show_type),\n      commentType: firstDefined(comment.comment_type),\n      trackId: firstDefined(comment.track_id),\n      authorId: firstDefined(user.user_id, user.userid, user.id),\n      authorName: firstDefined(user.nickname, user.name),\n      authorRedId: firstDefined(user.red_id, user.redId),\n      authorAvatar: firstDefined(user.images, user.image, user.avatar),\n      atUsers: Array.isArray(comment.at_users) ? comment.at_users : [],\n      subComments: Array.isArray(comment.sub_comments) ? comment.sub_comments : [],\n      hashTags: Array.isArray(comment.hash_tags) ? comment.hash_tags : [],\n      rawComment: comment,\n    };\n  });\n\n  results.push({\n    json: {\n      noteId: cfg.noteId,\n      requestedMaxComments: maxComments,\n      extractedCount: normalized.length,\n      totalCommentCount: Number(firstDefined(data.comment_count, data.comments_count, normalized.length) || 0),\n      level1CommentCount: Number(firstDefined(data.comment_count_l1, normalized.length) || 0),\n      hasMore: Boolean(data.has_more ?? false),\n      nextCursor: firstDefined(data.cursor),\n      currentSortStrategy: firstDefined(data.current_sort_strategy),\n      allSortStrategies: Array.isArray(data.all_sort_strategies) ? data.all_sort_strategies : [],\n      userId: firstDefined(data.user_id),\n      pageContext: firstDefined(data.page_context),\n      comments: normalized,\n      raw: payload,\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "cc11702b-19e0-4060-b957-7abe017f4c9e",
      "name": "Output Final Comment Data",
      "type": "n8n-nodes-base.set",
      "position": [
        6800,
        1360
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "4b8e2e1f-4a5e-4634-83a3-d4bae94a92af",
  "connections": {
    "Start Workflow": {
      "main": [
        [
          {
            "node": "Set API and Comment Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse and Build Comment List": {
      "main": [
        [
          {
            "node": "Output Final Comment Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API and Comment Parameters": {
      "main": [
        [
          {
            "node": "Fetch Xiaohongshu Comments via API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Xiaohongshu Comments via API": {
      "main": [
        [
          {
            "node": "Output Raw API Response",
            "type": "main",
            "index": 0
          },
          {
            "node": "Parse and Build Comment List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}