{
  "nodes": [
    {
      "id": "403c12fe-20b6-4fc5-93ee-ab9b26c304c8",
      "name": "If invalid TikTok link",
      "type": "n8n-nodes-base.if",
      "position": [
        -272,
        112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8eef8a96-b0b9-4338-9799-3281f97eadda",
              "operator": {
                "type": "string",
                "operation": "notContains"
              },
              "leftValue": "={{ $json['TikTok creator/video link:'] }}",
              "rightValue": "tiktok"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "73c6e396-f835-446f-8ef5-0ca3daaf230f",
      "name": "Extract username of TikTok creator/video link",
      "type": "n8n-nodes-base.set",
      "position": [
        576,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8b5ea5c9-b73f-4130-8c5e-16af778ac490",
              "name": "username",
              "type": "string",
              "value": "={{ $json['TikTok creator/video link:'].match(/@([^/?]+)/)[1] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b5532f7c-73a7-4ecc-8abe-fadb27837c79",
      "name": "Get  final link of TikTok video",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        304
      ],
      "parameters": {
        "url": "={{ $('On form submission').item.json['TikTok creator/video link:'] }}",
        "options": {
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          },
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ad8d1445-be09-4be1-9d81-625b70f88a6b",
      "name": "Extract final TikTok video link",
      "type": "n8n-nodes-base.set",
      "position": [
        368,
        304
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c9662b84-fe9a-4f8c-a49f-d0b5b63423ab",
              "name": "TikTok creator/video link:",
              "type": "string",
              "value": "={{ $json[\"data\"].match(/href=\"([^\"]+)\"/)[1] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "bf6c655f-fe4e-42fe-87ea-2fa854972305",
      "name": "If final TikTok link",
      "type": "n8n-nodes-base.if",
      "position": [
        -32,
        192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8eef8a96-b0b9-4338-9799-3281f97eadda",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $('On form submission').item.json['TikTok creator/video link:'] }}",
              "rightValue": "@"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6b26b51d-eb28-43bd-88bb-72de572577d8",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -576,
        112
      ],
      "parameters": {
        "options": {
          "buttonLabel": "Get creator's username",
          "appendAttribution": false
        },
        "formTitle": "TikTok creator/video link:",
        "formFields": {
          "values": [
            {
              "fieldLabel": "TikTok creator/video link:",
              "placeholder": "https://[...]tiktok.com/[...]",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "formDescription": "You can use any TikTok link format of video or creator.\n\nE.g.:\n\n-> https://www.tiktok.com/@dotXYZZ\n\n-> https://www.tiktok.com/@dotXYZZ?_t=ZD-90v&_r=1\n\n-> https://vm.tiktok.com/GDxXXXXXXX16/\n\n-> https://www.tiktok.com/@dotXYZZ/video/436264524234?_t=YH-92meeug&_r=1\n\n-> ..."
      },
      "typeVersion": 2.3
    },
    {
      "id": "b18bd6ce-a0ed-4347-aa96-53ab85af6447",
      "name": "Invalid link",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        128,
        0
      ],
      "parameters": {
        "errorMessage": "The link is invalid!"
      },
      "typeVersion": 1
    },
    {
      "id": "00dc2cae-06bf-4b32-9804-6da01d394a93",
      "name": "Inform the link is invalid",
      "type": "n8n-nodes-base.form",
      "position": [
        -32,
        0
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "Error!",
        "completionMessage": "The link is invalid!"
      },
      "typeVersion": 2.3
    },
    {
      "id": "7118efb8-ef17-4064-948c-dc67e7acec16",
      "name": "If the username is null",
      "type": "n8n-nodes-base.if",
      "position": [
        768,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "28c1c38b-c8bf-42eb-8e72-4211db879f15",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.username }}",
              "rightValue": ""
            },
            {
              "id": "003bc087-4f80-4277-a1f3-5c4e5dbf273c",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.username }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "7078cbb5-fa2a-4484-a8ad-b4d2d18005a3",
      "name": "Username is null/empty",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1216,
        48
      ],
      "parameters": {
        "errorMessage": "An error ocurred while retrieving the creator's username!"
      },
      "typeVersion": 1
    },
    {
      "id": "fb4e51b1-8318-4650-9302-375f09c20708",
      "name": "Inform an error retrieving the username",
      "type": "n8n-nodes-base.form",
      "position": [
        1008,
        48
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "Error!",
        "completionMessage": "An error ocurred while retrieving the creator's username."
      },
      "typeVersion": 2.3
    },
    {
      "id": "563f8214-4524-422f-a57e-73dd515f4441",
      "name": "Display the creator's username",
      "type": "n8n-nodes-base.form",
      "position": [
        1008,
        288
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "Creator's username found!",
        "completionMessage": "=<br>\nThe creator's username is: <strong>{{ $json.username }}</strong>\n<br>\n<br>\nThis means their profile link is <em>https://www.tiktok.com/@{{ $json.username }}</em>"
      },
      "typeVersion": 2.3
    },
    {
      "id": "c57b0292-b789-4b77-8323-900a0761ea71",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 336,
        "height": 352,
        "content": "## Decide the input method\n\n**If you don't want to use a form**, you can perfectly change this node to another one also called _\"On form submission\"_ that gets the link and assigns it to a variable called _\"TikTok creator/video link:\"_."
      },
      "typeVersion": 1
    },
    {
      "id": "70530a04-1c09-4d5b-9f53-40f7299fab75",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -192
      ],
      "parameters": {
        "color": 5,
        "width": 352,
        "height": 352,
        "content": "## Decide what happens when the link is invalid\n\n**If you don't want to inform the user through the form** that the link is invalid, you can change this section."
      },
      "typeVersion": 1
    },
    {
      "id": "f3750292-c1de-4e3f-96f2-d4f29a61616c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -48
      ],
      "parameters": {
        "width": 2048,
        "height": 560,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "48a10b71-373a-4050-b517-aeedad827793",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        -176
      ],
      "parameters": {
        "color": 5,
        "width": 432,
        "height": 416,
        "content": "## Decide what happens when the username retrieval fails\n\n**If you don't want to inform the user through the form** that the an unexcpeted error ocurred while retrieving the username, you can change this section."
      },
      "typeVersion": 1
    },
    {
      "id": "2ee12dba-cd19-41b2-8090-9e74b6256f86",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        256
      ],
      "parameters": {
        "color": 5,
        "width": 432,
        "height": 416,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Decide where to send the creator's username\n\n**If you don't want to inform the user through the form** about the retrieved username ( _{{ $json.username }}_ ), you can send the username somewhere else."
      },
      "typeVersion": 1
    },
    {
      "id": "99f54d0a-05e3-4972-958e-269bfcbabe44",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        0
      ],
      "parameters": {
        "color": 2,
        "width": 496,
        "height": 464,
        "content": "## What does this do?\n\nImagine you want to **automate a task** where, based on a TikTok video link, **you must retrieve the username of the creator of that video**.\n\nMany people may think that it's enough to get the \"@\" part of the link but that's not the case always. TikTok's iOS and Android app have **specific link formats** that are easier to share with others but, at the same time, it makes our task of retrieving creators way harder.\n\n**In solution to this problem**, this simple workflow makes a HTTP protocol request to retrieve the original link of the video hosted on _www.tiktok.com_ instead of the default mobile app's subdomain _vm.tiktok.com_. Then, we can in fact remove the attributes of the link and extract the handle correctly.\n\n**Note that we extract the username (AND NOT THE NICKNAME) without the \"@\".**\n\nOnce we have our username, we can simply access to their profile from then on using _\"https://www.tiktok.com/@{{ $json.username }}\"_."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "If invalid TikTok link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If final TikTok link": {
      "main": [
        [
          {
            "node": "Extract username of TikTok creator/video link",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get  final link of TikTok video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If invalid TikTok link": {
      "main": [
        [
          {
            "node": "Inform the link is invalid",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If final TikTok link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If the username is null": {
      "main": [
        [
          {
            "node": "Inform an error retrieving the username",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Display the creator's username",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inform the link is invalid": {
      "main": [
        [
          {
            "node": "Invalid link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract final TikTok video link": {
      "main": [
        [
          {
            "node": "Extract username of TikTok creator/video link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get  final link of TikTok video": {
      "main": [
        [
          {
            "node": "Extract final TikTok video link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inform an error retrieving the username": {
      "main": [
        [
          {
            "node": "Username is null/empty",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract username of TikTok creator/video link": {
      "main": [
        [
          {
            "node": "If the username is null",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}