{
  "id": "IWZfER17dg4XDFVA",
  "name": "Resolve Xiaohongshu share links with JustOneAPI",
  "tags": [],
  "nodes": [
    {
      "id": "0ac3f76d-0e41-4e26-b5fe-4a07655e2db7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3248,
        1344
      ],
      "parameters": {
        "width": 480,
        "height": 640,
        "content": "## Resolve Xiaohongshu share links with JustOneAPI\n\n### How it works\n\n1. The workflow is triggered manually.\n2. Input parameters are prepared for the API call.\n3. The Xiaohongshu share link is resolved via HTTP request.\n4. The raw result is output for debugging.\n5. The resolved link is processed and formatted.\n6. The final resolved share link is output.\n\n### Setup steps\n\n- - [ ] Configure the JustOneAPI base URL in the 'Prepare API and Share Link Inputs' node\n- - [ ] Ensure the Xiaohongshu share link input field is correctly mapped\n\n### Customization\n\nThe 'Build Resolved Share Link Output' node can be customized to modify the output format of the resolved share link."
      },
      "typeVersion": 1
    },
    {
      "id": "fef35c93-bc5f-4ada-ae8b-c6246f6a77bb",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3808,
        1344
      ],
      "parameters": {
        "color": 7,
        "height": 96,
        "content": "## Workflow Trigger\n\nManually initiates the workflow execution."
      },
      "typeVersion": 1
    },
    {
      "id": "ca2900bb-ffdd-4512-b1bf-19a2d3d21938",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4160,
        1344
      ],
      "parameters": {
        "color": 7,
        "height": 112,
        "content": "## Prepare API Inputs\n\nSets up the required parameters for the API call."
      },
      "typeVersion": 1
    },
    {
      "id": "35c285df-736b-4682-a56a-518f2ea9828d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4496,
        1344
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 112,
        "content": "## Resolve Share Link\n\nMakes the HTTP request to resolve the Xiaohongshu share link."
      },
      "typeVersion": 1
    },
    {
      "id": "ca87961e-d7d8-4e25-9a83-1c6bcd9cdc1a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4848,
        1344
      ],
      "parameters": {
        "color": 7,
        "height": 112,
        "content": "## Output Raw Result\n\nOutputs the raw API response for debugging purposes."
      },
      "typeVersion": 1
    },
    {
      "id": "60b6460e-71a5-40b0-8227-ea08b54b5669",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4848,
        1664
      ],
      "parameters": {
        "color": 7,
        "height": 128,
        "content": "## Process Resolved Link\n\nProcesses and formats the resolved share link."
      },
      "typeVersion": 1
    },
    {
      "id": "a47cacc1-8c52-4ef3-aae4-54786e42ecc6",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5168,
        1664
      ],
      "parameters": {
        "color": 7,
        "height": 96,
        "content": "## Output Final Result\n\nOutputs the final formatted resolved share link."
      },
      "typeVersion": 1
    },
    {
      "id": "50b35719-b402-476c-b3e7-5800d3517b38",
      "name": "Start Workflow Execution",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        3856,
        1600
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "a1cd0109-8984-492f-8342-0deeeee6e775",
      "name": "Set API and Share Link Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        4208,
        1600
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"baseUrl\": \"https://api.justoneapi.com\",\n  \"token\": \"PASTE_YOUR_TOKEN_HERE\",\n  \"shareUrl\": \"http://xhslink.com/m/8VnNcVX9y1\"\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "467fc52d-0f4f-4d06-a92c-bc105bc3eafb",
      "name": "Fetch Resolved Xiaohongshu Link",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4576,
        1600
      ],
      "parameters": {
        "url": "={{$json.baseUrl + '/api/xiaohongshu/share-url-transfer/v1'}}",
        "options": {
          "timeout": 60000,
          "redirect": {
            "redirect": {}
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "token",
              "value": "={{$json.token}}"
            },
            {
              "name": "shareUrl",
              "value": "={{$json.shareUrl}}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "70ff1c3d-3392-4f0c-bc73-ec828b77aa84",
      "name": "Store Raw Share Link Data",
      "type": "n8n-nodes-base.set",
      "position": [
        4896,
        1472
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "fe590549-e29b-4b04-a216-249daf13928d",
      "name": "Format Resolved Share Link Data",
      "type": "n8n-nodes-base.code",
      "position": [
        4896,
        1808
      ],
      "parameters": {
        "jsCode": "const cfg = $('Set API and Share Link Parameters').first().json;\nconst rows = $input.all();\nconst output = [];\n\nfor (const row of rows) {\n  const root = row.json || {};\n  const data = root?.data || {};\n\n  const redirectUrl = data?.redirect_url || data?.redirectUrl || data?.resolved_url || data?.url || data?.target_url || data?.jump_url || data?.origin_url || '';\n  const originalUrl = cfg?.shareUrl || data?.original_url || data?.source_url || '';\n\n  let normalizedUrl = '';\n  let noteId = data?.note_id || data?.noteId || data?.id || '';\n  let userId = data?.user_id || data?.userId || '';\n  let xsecToken = data?.xsec_token || data?.xsecToken || '';\n  let linkType = data?.type || data?.link_type || data?.object_type || '';\n  let shareChannel = '';\n  let shareSource = '';\n  let appPlatform = '';\n  let appVersion = '';\n  let title = data?.title || '';\n\n  if (redirectUrl) {\n    try {\n      const parsed = new URL(redirectUrl);\n      normalizedUrl = `${parsed.origin}${parsed.pathname}`;\n\n      const pathParts = parsed.pathname.split('/').filter(Boolean);\n      const itemIndex = pathParts.indexOf('item');\n      if (!noteId && itemIndex >= 0 && pathParts[itemIndex + 1]) {\n        noteId = pathParts[itemIndex + 1];\n      }\n\n      if (!xsecToken) {\n        xsecToken = parsed.searchParams.get('xsec_token') || '';\n      }\n      if (!linkType) {\n        linkType = parsed.searchParams.get('type') || '';\n      }\n      shareChannel = parsed.searchParams.get('share_channel') || '';\n      shareSource = parsed.searchParams.get('xsec_source') || '';\n      appPlatform = parsed.searchParams.get('app_platform') || '';\n      appVersion = parsed.searchParams.get('app_version') || '';\n      userId = userId || parsed.searchParams.get('user_id') || '';\n    } catch (error) {\n      normalizedUrl = redirectUrl;\n    }\n  }\n\n  output.push({\n    json: {\n      baseUrl: cfg?.baseUrl || '',\n      originalShareUrl: originalUrl,\n      code: root?.code ?? null,\n      message: root?.message ?? null,\n      recordTime: root?.recordTime || '',\n      redirectUrl,\n      normalizedUrl,\n      noteId,\n      userId,\n      xsecToken,\n      linkType,\n      title,\n      shareChannel,\n      shareSource,\n      appPlatform,\n      appVersion,\n      rawData: data,\n      raw: root\n    }\n  });\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "a62d2adf-04a6-452b-a3c5-f7bbd2b8270d",
      "name": "Output Final Resolved Link Data",
      "type": "n8n-nodes-base.set",
      "position": [
        5232,
        1808
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{$json}}"
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "a0d127a0-0f7d-4cf1-9ae5-72ea0b20902a",
  "connections": {
    "Start Workflow Execution": {
      "main": [
        [
          {
            "node": "Set API and Share Link Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Resolved Xiaohongshu Link": {
      "main": [
        [
          {
            "node": "Store Raw Share Link Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Format Resolved Share Link Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Resolved Share Link Data": {
      "main": [
        [
          {
            "node": "Output Final Resolved Link Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set API and Share Link Parameters": {
      "main": [
        [
          {
            "node": "Fetch Resolved Xiaohongshu Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}