{
  "id": "ayHCunchTFsKpS9N",
  "name": "Get Xiaohongshu comment replies with JustOneAPI",
  "tags": [],
  "nodes": [
    {
      "id": "43918cf8-ec8c-49fd-ad1f-79ca9b5b9f73",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2272,
        528
      ],
      "parameters": {
        "width": 512,
        "height": 496,
        "content": "## Get Xiaohongshu comment replies with JustOneAPI\n\n### How it works\n\n1. The workflow is triggered manually.\n2. It prepares API and comment reply inputs.\n3. It fetches Xiaohongshu comment replies via HTTP request.\n4. It processes the raw response to build a comment reply list.\n5. It outputs the final comment reply list.\n\n### Setup steps\n\n- - [ ] Configure the JustOneAPI credentials in the HTTP Request node.\n- - [ ] Set the correct base URL and endpoint for Xiaohongshu API in the HTTP Request node.\n- - [ ] Ensure the 'Prepare API and Comment Reply Inputs' node has the required fields for the API call.\n\n### Customization\n\nYou can customize the API endpoint and query parameters in the 'Prepare API and Comment Reply Inputs' and 'Fetch Xiaohongshu Comment Replies' nodes to fetch different types of data or from different endpoints."
      },
      "typeVersion": 1
    },
    {
      "id": "9434e0b4-0352-4520-a3da-0ff472936806",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2832,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 80,
        "content": "## Workflow Trigger\n\nManually initiates the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "c01374d1-cb2c-484f-b38e-81fab665b6b5",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3136,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 112,
        "content": "## Prepare API Inputs\n\nSets up the necessary fields and parameters for the API call."
      },
      "typeVersion": 1
    },
    {
      "id": "ea9bb428-c16c-4b71-b454-54a82b02000a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3488,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 144,
        "content": "## Fetch Comment Replies\n\nMakes an HTTP request to fetch Xiaohongshu comment replies."
      },
      "typeVersion": 1
    },
    {
      "id": "239c7977-2606-400a-be77-efad7be7fd88",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3824,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 144,
        "content": "## Process Raw Response\n\nBuilds a structured comment reply list from the raw API response."
      },
      "typeVersion": 1
    },
    {
      "id": "ec8bb0c6-f04d-4dbe-a9b3-419e32c53611",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4112,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 96,
        "content": "## Output Results\n\nOutputs the final processed comment reply list and raw response."
      },
      "typeVersion": 1
    },
    {
      "id": "a5690e33-ca25-4af0-8e27-1b7682b13e39",
      "name": "Start Workflow Manually",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        2896,
        688
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c30b63b9-b8e4-4965-b78e-53635fecb166",
      "name": "Set API and Reply Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        3184,
        688
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"baseUrl\": \"https://api.justoneapi.com\",\n  \"token\": \"PASTE_YOUR_TOKEN_HERE\",\n  \"noteId\": \"PASTE_YOUR_NOTE_ID_HERE\",\n  \"commentId\": \"PASTE_YOUR_COMMENT_ID_HERE\",\n  \"lastCursor\": \"\"\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "47dc59a0-5700-46e6-81fb-e6cc8c28810f",
      "name": "Fetch Xiaohongshu Replies via API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3536,
        688
      ],
      "parameters": {
        "url": "={{$json.baseUrl + '/api/xiaohongshu/get-note-sub-comment/v2'}}",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "token",
              "value": "={{$json.token}}"
            },
            {
              "name": "noteId",
              "value": "={{$json.noteId}}"
            },
            {
              "name": "commentId",
              "value": "={{$json.commentId}}"
            },
            {
              "name": "lastCursor",
              "value": "={{$json.lastCursor}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5b0ff50b-84f6-440b-a45b-862097108c70",
      "name": "Output Raw Reply Data",
      "type": "n8n-nodes-base.set",
      "position": [
        4144,
        912
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "551eabaf-ff98-4b0b-a2f4-b23b0bcf578b",
      "name": "Parse Reply Data into List",
      "type": "n8n-nodes-base.code",
      "position": [
        3872,
        688
      ],
      "parameters": {
        "jsCode": "\nconst rows = $input.all();\n\nfunction pickArray(root) {\n  if (Array.isArray(root?.data?.comments)) return root.data.comments;\n  if (Array.isArray(root?.data?.sub_comments)) return root.data.sub_comments;\n  if (Array.isArray(root?.data?.replies)) return root.data.replies;\n  if (Array.isArray(root?.data)) return root.data;\n  return [];\n}\n\nfunction pickHasMore(root) {\n  return root?.data?.has_more ?? false;\n}\n\nfunction pickCursor(root) {\n  return root?.data?.cursor ?? '';\n}\n\nreturn rows.flatMap(item => {\n  const root = item.json || {};\n  const replies = pickArray(root);\n  const hasMore = pickHasMore(root);\n  const nextCursor = pickCursor(root);\n  const cfg = $('Set API and Reply Parameters').first().json;\n\n  return replies.map((reply, index) => {\n    const user = reply.user || {};\n    const replyUser = reply.reply_comment?.user || {};\n    const atUsers = Array.isArray(reply.at_users) ? reply.at_users : [];\n    const subComments = Array.isArray(reply.sub_comments) ? reply.sub_comments : [];\n\n    return {\n      json: {\n        requestedNoteId: cfg.noteId || '',\n        requestedCommentId: cfg.commentId || '',\n        requestedLastCursor: cfg.lastCursor || '',\n        replyIndex: index + 1,\n        replyId: reply.id || '',\n        noteId: reply.note_id || cfg.noteId || '',\n        rootCommentId: reply.root_comment_id || cfg.commentId || '',\n        parentCommentId: reply.parent_comment_id || '',\n        content: reply.content || '',\n        likeCount: reply.like_count ?? 0,\n        subCommentCount: reply.sub_comment_count ?? 0,\n        replyTime: reply.time ?? 0,\n        ipLocation: reply.ip_location || '',\n        liked: reply.liked ?? false,\n        collected: reply.collected ?? false,\n        status: reply.status ?? '',\n        showType: reply.show_type || '',\n        commentType: reply.comment_type ?? '',\n        userId: user.userid || '',\n        userNickname: user.nickname || '',\n        userRedId: user.red_id || '',\n        userAvatar: user.images || '',\n        replyToUserId: replyUser.userid || '',\n        replyToUserNickname: replyUser.nickname || '',\n        atUsers,\n        subComments,\n        hasMore,\n        nextCursor,\n        raw: reply\n      }\n    };\n  });\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "28bd3f3e-f4ac-4d5d-b2d1-bfb28c381f3c",
      "name": "Output Final Reply List",
      "type": "n8n-nodes-base.set",
      "position": [
        4480,
        688
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "84f77ded-269d-49ce-b1d6-85b34e141c21",
  "connections": {
    "Start Workflow Manually": {
      "main": [
        [
          {
            "node": "Set API and Reply Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Reply Data into List": {
      "main": [
        [
          {
            "node": "Output Final Reply List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API and Reply Parameters": {
      "main": [
        [
          {
            "node": "Fetch Xiaohongshu Replies via API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Xiaohongshu Replies via API": {
      "main": [
        [
          {
            "node": "Output Raw Reply Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Parse Reply Data into List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}