{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "863dc7cd-d022-4d64-b729-236c13c76498",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        260,
        0
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "7dc09659-1a38-4be4-baf8-e07312379205",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        500,
        0
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "3dd8c2aa-5dd9-4677-9ad7-a9cfa27c5da6",
      "name": "Profile Stats",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1040,
        20
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $now }}",
            "likes": "={{ $json.userProfile.heartCount }}",
            "videos": "={{ $json.userProfile.videoCount }}",
            "username": "={{ $('Loop Over Items').item.json.username }}",
            "followers ": "={{ $json.userProfile.followerCount }}",
            "following ": "={{ $json.userProfile.followingCount }}"
          },
          "schema": [
            {
              "id": "username",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "videos",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "videos",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "following ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "following ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "followers ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "followers ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "likes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "likes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "e8fc9e5c-5eb4-49fd-a60f-03ab3677f1c5",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ca95ec8a-8dba-4821-a3d6-9fc96bd39fdc",
      "name": "Fetch Profile",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        800,
        20
      ],
      "parameters": {
        "url": "https://tiktok-api42.p.rapidapi.com/user_profile.php",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "username",
              "value": "={{ $json.username }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "tiktok-api42.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "your key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3cceba32-d50e-46a6-8f66-ea36ee42bdb9",
      "name": "Fetch Videos",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        440
      ],
      "parameters": {
        "url": "https://tiktok-api42.p.rapidapi.com/view_count.php",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "username",
              "value": "={{ $('Loop Over Items').item.json.username }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "tiktok-api42.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "your key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "97890005-4e87-4204-8779-e9404fd3a75f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        -180
      ],
      "parameters": {
        "width": 600,
        "height": 1280,
        "content": "# \ud83d\udcca TikTok Analytics Automation \n\n## \ud83d\udcdd Description\nThis workflow in n8n automates the process of retrieving TikTok user data using the RapidAPI service, processes the data in batches, and writes analytics to a Google Sheet. It runs on a scheduled interval and handles multiple TikTok usernames.\n\n---\n\n## \u2705 Benefits\n- \u23f0 Automates daily or scheduled TikTok profile analytics.\n- \ud83d\udce4 Fetches profile and video stats via RapidAPI.\n- \ud83d\udccb Reads usernames from a source Google Sheet.\n- \ud83d\udcc8 Appends processed results to a destination Google Sheet.\n- \ud83d\udd04 Processes multiple users efficiently using batch loops.\n- \ud83e\udde9 Easy to customize for other platforms or endpoints.\n\n---\n\n## \ud83d\udd0d Use Case\n- Social media managers tracking influencer performance.\n- Marketing agencies generating automated TikTok reports.\n- Competitor analysis for TikTok growth metrics.\n\n---\n\n## \u2699\ufe0f Node Overview\n\n| Node Name          | Type                 | Description                                                                 |\n|--------------------|----------------------|-----------------------------------------------------------------------------|\n| **Schedule Trigger** | Trigger Node         | Starts the workflow on a defined schedule.                                 |\n| **Google Sheets**  | Google Sheets (Read)  | Reads a list of usernames from a Google Sheet.                             |\n| **Loop Over Items** | Utility (Batch Loop) | Loops over each username for processing.                                   |\n| **Fetch Profile**  | HTTP Request          | Calls `user_profile.php` on RapidAPI to fetch TikTok profile data.         |\n| **Fetch Videos**   | HTTP Request          | Calls `view_count.php` on RapidAPI to retrieve video analytics.            |\n| **Google Sheets1** | Google Sheets (Write) | Appends processed data to a results Google Sheet.                          |\n\n---\n\n## \ud83e\udde0 Tips\n- For heavy loads, consider adding error handling and retry logic.\n- You can log failed users in a separate sheet for review.\n- Use environment variables in n8n for API keys to keep credentials safe.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "26c5211b-bbf7-4cfa-998e-f2bdb0a94fa2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -200
      ],
      "parameters": {
        "height": 360,
        "content": "**Schedule Trigger**  \n  Triggers the entire workflow based on a predefined schedule (e.g., daily or hourly).  \n  It ensures the process runs automatically without manual input."
      },
      "typeVersion": 1
    },
    {
      "id": "66fe6fa5-7266-441d-a469-077715887da3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        -200
      ],
      "parameters": {
        "height": 360,
        "content": "**Google Sheets**  \n  Reads a list of TikTok usernames from a master Google Spreadsheet.  \n  These usernames are used as input for the TikTok API calls."
      },
      "typeVersion": 1
    },
    {
      "id": "83162a57-ffb5-4d24-ab62-288ff2e07d4e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        -200
      ],
      "parameters": {
        "height": 360,
        "content": "**Loop Over Items**  \n  Iterates over each row (username) retrieved from the sheet.  \n  Allows individual API requests for each username in sequence."
      },
      "typeVersion": 1
    },
    {
      "id": "f7a65bc9-e008-4e75-afe1-d477cd16d246",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        -200
      ],
      "parameters": {
        "height": 360,
        "content": "- **Fetch Profile**  \n  Calls the `user_profile.php` endpoint on RapidAPI for the current username.  \n  Retrieves user details like profile name, followers, etc. (if needed)."
      },
      "typeVersion": 1
    },
    {
      "id": "ec2d2a17-ce62-434c-9f2c-727cb7a9967f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        280
      ],
      "parameters": {
        "height": 320,
        "content": "- **Fetch Videos**  \n  Sends a POST request to `view_count.php` on RapidAPI using the current username.  \n  Returns total video stats such as views, posts count, and more."
      },
      "typeVersion": 1
    },
    {
      "id": "5fbbbff4-97b3-4aa5-92ca-b6f903660a6a",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        260
      ],
      "parameters": {
        "height": 340,
        "content": "- **Videos stats**  \n  Appends all the collected data (username, views, posts, date, etc.) to a result sheet.  \n  Acts as the final output log or dashboard for TikTok data tracking."
      },
      "typeVersion": 1
    },
    {
      "id": "2b69a5a1-2e3f-4646-a495-05b2f6c63f90",
      "name": "Videos Stats",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1300,
        440
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $now }}",
            "days": "={{ $json.days }}",
            "user": "={{ $json.user }}",
            "videos": "={{ $json.videos }}",
            "success": "={{ $json.success }}",
            "username": "={{ $('Loop Over Items').item.json.username }}",
            "total_posts": "={{ $json.total_posts }}",
            "total_views": "={{ $json.total_views }}"
          },
          "schema": [
            {
              "id": "username",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "success",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "success",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total_posts",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "total_posts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total_views",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "total_views",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "videos",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "videos",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "user",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "user",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "days",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "days",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "15d42bde-0278-47c7-9cb5-46d41056cac5",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        980,
        -200
      ],
      "parameters": {
        "height": 360,
        "content": "- **Profile Stats**  \n  Appends all the collected data  to a result sheet.  \n  Acts as the final output log or dashboard for TikTok data tracking."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Fetch Videos": {
      "main": [
        [
          {
            "node": "Videos Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Videos Stats": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Profile": {
      "main": [
        [
          {
            "node": "Profile Stats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Profile Stats": {
      "main": [
        [
          {
            "node": "Fetch Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Fetch Profile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}