# n8n-nodes-tiktok-custom

Custom TikTok nodes for n8n - Upload videos, manage products, and more without usage limits!

## Features

- 🎥 **TikTok Upload**: Upload videos with product anchors, captions, and scheduling
- 🛍️ **TikTok Products**: Manage your TikTok Shop products and showcase
- 🔒 **Session-based authentication**: Use your own TikTok account without API limits
- 💰 **Completely FREE**: No credits, no subscriptions, unlimited usage

## Installation

### Option 1: Via n8n Community Nodes (Recommended - Easiest! ✨)

1. Open your n8n instance
2. Go to **Settings** → **Community Nodes**
3. Click **Install a community node**
4. Enter: `n8n-nodes-tiktok-custom`
5. Click **Install**
6. Restart n8n
7. Done! The nodes will appear in your node panel

### Option 2: Manual Installation (For development)

#### Prerequisites
- n8n installed (self-hosted or Docker)
- Node.js and npm
- TypeScript compiler

#### Steps

1. **Clone or download this repository**
   ```bash
   cd path/to/n8n-nodes-tiktok-custom
   ```

2. **Install dependencies**
   ```bash
   npm install
   ```

3. **Build the project**
   ```bash
   npm run build
   ```

4. **Link to your n8n installation**
   ```bash
   npm link
   ```

5. **In your n8n directory, link the package**
   ```bash
   cd /path/to/your/n8n
   npm link n8n-nodes-tiktok-custom
   ```

6. **Restart n8n**
   ```bash
   n8n start
   ```

### Option 3: Via npm (Direct)

```bash
cd ~/.n8n
npm install n8n-nodes-tiktok-custom
# Restart n8n
```

## Getting TikTok Session Credentials

⚠️ **IMPORTANT**: This package uses session-based authentication from TikTok web. You need to extract cookies from your browser.

### How to get your session cookies:

1. **Login to TikTok**
   - Open https://www.tiktok.com in your browser
   - Login to your account

2. **Open DevTools**
   - Press `F12` or right-click → Inspect

3. **Navigate to Cookies**
   - Go to `Application` tab (Chrome) or `Storage` tab (Firefox)
   - Click on `Cookies` → `https://www.tiktok.com`

4. **Copy the required cookies**:
   - **sessionid** (required)
   - **msToken** (required)
   - **odin_tt** (optional, for some operations)

5. **In n8n, create TikTok Session credentials**
   - Paste the cookie values
   - Optionally customize User-Agent

## ⚠️ CRITICAL: Capturing Real TikTok Endpoints

**The endpoints in this code are PLACEHOLDERS!** Before using these nodes, you MUST capture the actual TikTok API endpoints using browser DevTools:

### How to capture endpoints:

1. **Open TikTok web** (https://www.tiktok.com)
2. **Open DevTools** (F12) → Network tab
3. **Filter by XHR/Fetch** requests
4. **Perform the action** you want to automate:
   - For upload: Go to upload page, start uploading a video
   - For products: Navigate to your shop/showcase
5. **Find the API requests** in the Network tab
6. **Right-click on the request** → Copy as cURL
7. **Analyze**:
   - URL endpoint
   - Request method (GET, POST, PUT)
   - Headers
   - Request body structure
8. **Update the code** in the corresponding node file with the real endpoints

### Example endpoints to capture:

- **Upload Video**:
  - Init: `POST /api/v1/web/project/create/`
  - Upload: `PUT <upload_url>`
  - Publish: `POST /api/v1/item/create/`

- **Get Products**:
  - `GET /api/commerce/v1/creator/products`

- **Product with Anchor**:
  - `POST /api/v1/item/create/` with `anchors` in body

## Usage

### TikTok Products Node

Get a list of products from your showcase:

```json
{
  "operation": "getProducts",
  "count": 10,
  "offset": 0
}
```

### TikTok Upload Node

Upload a video with product anchor:

```json
{
  "videoSource": "binaryData",
  "binaryProperty": "data",
  "caption": "Check out this amazing product!",
  "visibility": 0,
  "allowComment": true,
  "productAnchors": {
    "anchor": [
      {
        "productId": "1234567890",
        "displayName": "My Product"
      }
    ]
  }
}
```

## Example Workflow

Replace your existing `@dlir2404/n8n-nodes-tiktok` workflow with:

1. **Manual Trigger** or any trigger
2. **TikTok Products** (Get Products) - Get your products
3. **HTTP Request** - Download video
4. **TikTok Upload** - Upload with product anchor

## Limitations & Important Notes

⚠️ **Session-based limitations**:
- Cookies expire periodically - you'll need to refresh them
- TikTok may change their internal API without notice
- This is an unofficial method - use at your own risk
- Rate limiting may apply

⚠️ **Endpoints**:
- You MUST capture real endpoints from browser before use
- The code contains placeholder URLs that won't work without modification

## Development

### Project Structure

```
n8n-nodes-tiktok-custom/
├── credentials/
│   └── TikTokSession.credentials.ts
├── nodes/
│   └── TikTok/
│       ├── TikTokUpload.node.ts
│       └── TikTokProducts.node.ts
├── package.json
├── tsconfig.json
└── README.md
```

### Build

```bash
npm run build
```

### Watch mode (for development)

```bash
npm run dev
```

## Troubleshooting

### "Authentication failed" error
- Your session cookies have expired
- Re-extract cookies from browser and update credentials

### "Rate limit exceeded"
- TikTok is temporarily blocking your requests
- Wait a few minutes before retrying
- Consider adding delays between operations

### Node doesn't appear in n8n
- Make sure you ran `npm run build`
- Verify the link with `npm link` and in n8n directory
- Restart n8n completely
- Check n8n logs for errors

## Contributing

This is an educational project to demonstrate how to create custom n8n nodes. Feel free to:
- Capture and share real TikTok endpoints
- Add more operations (analytics, account management, etc.)
- Improve error handling
- Add tests

## License

MIT

## Disclaimer

This package is for educational purposes. It uses unofficial TikTok web APIs through session authentication. Use responsibly and in accordance with TikTok's Terms of Service.
