# TikTok Hashtag API

> Get a TikTok hashtag with its post and view counts, and the posts under it, as JSON. 1 credit per call.

**Get a TikTok hashtag** with its post and view counts, and **the posts under it**.

```
GET https://api.handlehaul.com/v1/tiktok/hashtags/{tag}
GET https://api.handlehaul.com/v1/tiktok/hashtags/{tag}/posts
```

- `GET /v1/tiktok/hashtags/{tag}`: id, name, description, post count, view count
- `GET /v1/tiktok/hashtags/{tag}/posts`: posts under the hashtag (up to 30 a page)

**Cost:** 1 credit per successful call (free from cache). An unknown hashtag answers `404` and is free.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `tag` | path | Hashtag name without `#` (`booktok`). For `/posts`, also the numeric `id` from the hashtag call; a name is looked up for you (no extra credit). |
| `cursor` | query | posts: `pagination.next_cursor` from the previous page. |
| `fresh` | query | `true` skips the cache. |
| `raw` | query | `true` returns TikTok's own JSON in `data`. |

## Response

```json
{
  "data": {
    "id": "5557519",
    "name": "booktok",
    "description": "",
    "post_count": 73117,
    "view_count": 1995200378,
    "url": "https://www.tiktok.com/tag/booktok"
  },
  "meta": {
    "request_id": "req_…",
    "cached": false,
    "cache_age_seconds": 0,
    "credits_charged": 1,
    "credits_remaining": 26943
  }
}
```

## Examples

```bash
curl "https://api.handlehaul.com/v1/tiktok/hashtags/booktok/posts" -H "X-Api-Key: $HANDLEHAUL_API_KEY"
```

```python
import os, requests
r = requests.get("https://api.handlehaul.com/v1/tiktok/hashtags/booktok/posts",
                 headers={"X-Api-Key": os.environ["HANDLEHAUL_API_KEY"]}, timeout=60)
r.raise_for_status()
for p in r.json()["data"]:
    print(p["url"], p["counts"]["views"])
```

```javascript
const res = await fetch("https://api.handlehaul.com/v1/tiktok/hashtags/booktok/posts", {
  headers: { "X-Api-Key": process.env.HANDLEHAUL_API_KEY },
});
const { data, meta } = await res.json();
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/tiktok/hashtags/booktok/posts");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("HANDLEHAUL_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.handlehaul.com/v1/tiktok/hashtags/booktok/posts", nil)
req.Header.Set("X-Api-Key", os.Getenv("HANDLEHAUL_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## FAQ

### How do I get TikTok hashtag views?
`GET /v1/tiktok/hashtags/{name}` returns `view_count` and `post_count`.
