How to Search Tweets Inside an X Community with TwexAPI
X Communities often contain narrower, more context-rich discussions than the main timeline. If you already know the community ID and want to find posts about a topic inside that community, use POST https://api.twexapi.io/twitter/community/search-tweets.
This endpoint is useful when a broad X search is too noisy. Instead of collecting every public mention of a keyword, you can search inside one community and review posts from people participating in that specific space.
What This Endpoint Does
POST /twitter/community/search-tweets searches tweets inside a single X Community.
The request has three required fields:
| Field | Type | Purpose |
|---|---|---|
community_id | string | The ID of the X Community you want to search. |
target_count | integer | The number of tweets to search for. Start with a modest value while tuning the query. |
query | string | The keyword or search phrase to match inside the community. |
Use it for focused workflows such as:
- Reviewing how a niche community discusses a product, topic, or release.
- Finding posts to include in a community report or internal digest.
- Tracking recurring questions in your own community.
- Comparing how the same topic appears across several communities.
The endpoint returns social posts. It does not replace moderation policy, customer research, or manual review.
Basic Request
curl --request POST \
--url https://api.twexapi.io/twitter/community/search-tweets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"community_id": "1234567890123456789",
"target_count": 50,
"query": "customer support"
}'A successful response includes code, msg, and data. Each item in data is a tweet object. Common fields include tweet_id, text, full_text, created_at, created_at_datetime, favorite_count, retweet_count, reply_count, quote_count, hashtags, cashtags, media, and user information.
1{
2 "code": 200,
3 "msg": "success",
4 "data": [
5 {
6 "tweet_id": "1803006263529541838",
7 "text": "Example community post about customer support",
8 "created_at_datetime": "2024-06-17T03:51:48.000Z",
9 "favorite_count": 18,
10 "retweet_count": 3,
11 "reply_count": 6,
12 "hashtags": ["support"]
13 }
14 ]
15}Python Client
Keep the client small. Let the caller decide how to rank, store, and review the returned posts.
1import os
2from typing import Any
3
4import requests
5
6API_URL = "https://api.twexapi.io/twitter/community/search-tweets"
7TOKEN = os.environ["TWEXAPI_BEARER_TOKEN"]
8
9def search_community_tweets(
10 community_id: str,
11 query: str,
12 *,
13 target_count: int = 50,
14) -> list[dict[str, Any]]:
15 payload = {
16 "community_id": community_id,
17 "target_count": target_count,
18 "query": query,
19 }
20
21 response = requests.post(
22 API_URL,
23 headers={
24 "Authorization": f"Bearer {TOKEN}",
25 "Content-Type": "application/json",
26 },
27 json=payload,
28 timeout=30,
29 )
30 response.raise_for_status()
31 return response.json().get("data", [])
32
33if __name__ == "__main__":
34 tweets = search_community_tweets(
35 "1234567890123456789",
36 "customer support",
37 target_count=25,
38 )
39 for tweet in tweets[:5]:
40 text = tweet.get("full_text") or tweet.get("text") or ""
41 print(tweet.get("tweet_id"), text[:140])Normalize Posts for Review
Do not start by building a complicated dashboard. First, turn each tweet into a stable row that an analyst or community manager can review.
1def to_review_row(tweet: dict[str, Any]) -> dict[str, Any]:
2 favorite_count = tweet.get("favorite_count") or 0
3 retweet_count = tweet.get("retweet_count") or 0
4 reply_count = tweet.get("reply_count") or 0
5 quote_count = tweet.get("quote_count") or 0
6 engagement = favorite_count + retweet_count + reply_count + quote_count
7
8 return {
9 "tweet_id": tweet.get("tweet_id"),
10 "created_at": tweet.get("created_at_datetime") or tweet.get("created_at"),
11 "engagement": engagement,
12 "hashtags": ", ".join(tweet.get("hashtags") or []),
13 "text": tweet.get("full_text") or tweet.get("text") or "",
14 "url": f"https://x.com/i/status/{tweet.get('tweet_id')}",
15 }
16
17tweets = search_community_tweets(
18 "1234567890123456789",
19 "pricing",
20 target_count=100,
21)
22rows = [to_review_row(tweet) for tweet in tweets]
23rows.sort(key=lambda row: row["engagement"], reverse=True)
24
25for row in rows[:10]:
26 print(row["engagement"], row["url"], row["text"][:100])Store the raw tweet payload as well as the normalized row. The raw payload lets you revisit fields later without re-running the search.
Multi-Community Comparison
If you need to compare the same query across several communities, keep the loop explicit. This makes it easier to log failures and avoid mixing results from different audiences.
1communities = {
2 "1234567890123456789": "Product builders",
3 "2345678901234567890": "Support leaders",
4 "3456789012345678901": "AI operators",
5}
6
7query = "onboarding"
8summary = []
9
10for community_id, name in communities.items():
11 tweets = search_community_tweets(community_id, query, target_count=50)
12 rows = [to_review_row(tweet) for tweet in tweets]
13 total_engagement = sum(row["engagement"] for row in rows)
14 summary.append(
15 {
16 "community_id": community_id,
17 "name": name,
18 "tweet_count": len(rows),
19 "total_engagement": total_engagement,
20 }
21 )
22
23for item in sorted(summary, key=lambda row: row["total_engagement"], reverse=True):
24 print(item["name"], item["tweet_count"], item["total_engagement"])Use the numbers as a triage signal, not as a conclusion. A smaller community may have fewer posts but better context.
Monitoring Pattern
For ongoing monitoring, schedule a query and deduplicate by tweet_id:
- Search the community with a narrow
query. - Store every returned
tweet_id. - Skip rows you have already processed.
- Rank new rows by engagement and recency.
- Send only the highest-priority posts to a human review queue.
If you want an unfiltered feed for a community, TwexAPI also exposes community tweet endpoints such as GET /twitter/community/{community_id}/tweets/{tweet_type}/{target_count} and paginated community tweet retrieval. Use the search endpoint when the keyword matters more than a complete feed.
Common Pitfalls
- Do not pass a community slug when the endpoint requires
community_id. - Keep
queryspecific. One-word queries often return mixed intent. - Treat
target_countas an upper bound for collection, not a guarantee that every result will be useful. - Store
tweet_idas the dedupe key before you run scheduled jobs. - Review the posts before using them in reports. Community posts can contain jokes, sarcasm, off-topic replies, and private context.
Wrap-up
POST /twitter/community/search-tweets is best for focused research inside one X Community. Give it a community_id, a query, and a target_count; then normalize the response into review rows before drawing conclusions.
That framing keeps the workflow practical: collect the posts, keep the context, and let humans decide what matters.