Pipedream
Build Pipedream workflow automation for tweet search, profiles, trending tweets, HTTP triggers, and approved posts through TwexAPI.
Build a Pipedream Twitter integration for searches, profiles, trending tweets, and approved posts. TwexAPI supplies one REST API and one API key for every workflow.
Choose a webhook trigger for agent handoffs, a schedule trigger for recurring searches, or inline code steps when you need custom normalization.
Choose a Pipedream automation pattern
HTTP trigger + code step
Receive strict JSON from an MCP agent, normalize rows, and route to Slack or Sheets.
Scheduled REST reads
Call TwexAPI on a cadence for tweet search or trend reports.
Private component package
Package repeated authenticated requests when the whole team needs the same actions.
Split searches, webhook handoffs, follower exports, and approved writes into separate workflows. Smaller workflows expose errors and rate limits more clearly.
Prerequisites
- TwexAPI API key
- Pipedream account
- Optional connected accounts for Slack, Google Sheets, Airtable, or a database
- Optional MCP-capable agent connected to
https://api.twexapi.io/mcp
Serverless API integration
Start every TwexAPI request at https://api.twexapi.io. Send the API key through the Authorization: Bearer header. Keep keys in Pipedream environment variables, not step exports or logs.
export TWEXAPI_API_KEY="YOUR_API_KEY"
Use GET /balance as the first authentication check. It verifies the API key without changing an X account.
Shared request helper
export default defineComponent({
props: {
twexapi: {
type: "string",
label: "TwexAPI API Key",
secret: true,
},
},
methods: {
async twexapiRequest($, { method, path, body, params }) {
const url = new URL(`https://api.twexapi.io${path}`);
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== null) {
url.searchParams.set(key, String(value));
}
});
}
const response = await fetch(url, {
method,
headers: {
Authorization: `Bearer ${this.twexapi}`,
"Content-Type": "application/json",
},
body: body ? JSON.stringify(body) : undefined,
});
if (!response.ok) {
throw new Error(`TwexAPI request failed with HTTP ${response.status}`);
}
return response.json();
},
},
});
Starter actions
| Action | TwexAPI route |
|---|---|
| Search tweets | POST /twitter/advanced_search/page |
| Get user profile | GET /twitter/{screen_name}/about |
| Search users | GET /twitter/search-user/{keyword}/{target_count} |
| Get trends | GET /twitter/global-trending/tweets |
| List followers | POST /v3/twitter/users/followers |
| Create tweet | POST /twitter/tweets/create |
Search tweets code step
export default defineComponent({
async run({ steps, $ }) {
const response = await fetch("https://api.twexapi.io/twitter/advanced_search/page", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TWEXAPI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
searchTerms: ["AI agents lang:en"],
sortBy: "Latest",
nextCursor: "",
}),
});
if (!response.ok) {
throw new Error(`TwexAPI request failed with HTTP ${response.status}`);
}
return response.json();
},
});
Webhook-first flow
- Create an HTTP trigger in Pipedream.
- Ask an MCP-capable agent to collect TwexAPI rows and return strict JSON.
- POST the JSON to the Pipedream endpoint.
- Normalize and dedupe rows in a code step.
JavaScript normalization step
export default defineComponent({
async run({ steps }) {
const payload = steps.trigger.event.body;
return (payload.tweets || []).map((tweet) => ({
id: tweet.tweet_id || tweet.id,
url: tweet.public_url ?? `https://x.com/i/web/status/${tweet.tweet_id || tweet.id}`,
author: tweet.author_username,
text: tweet.text || tweet.full_text,
created_at: tweet.created_at,
route_used: payload.route_used,
next_cursor: payload.next_cursor,
}));
},
});
Suggested MCP agent prompt:
Use Twexapi MCP to get quote tweets for tweet ID 1803006263529541838.
Return only JSON with route_used, source_tweet_id, has_more, next_cursor, and tweets.
Each tweet must include tweet_id, author_username, text, created_at, and public_url.
Do not call write endpoints.
Result handoff
Tweet pages
Export tweet_count, has_more, and next_cursor; return rows with tweet_id, text, author_username, and created_at.
Profile rows
Export user_id, username, name, follower counts, and verification fields.
Trend batches
Export country, topic, content tag, and tweet rows with workflow metadata.
Write actions
Preview with the CLI --dry-run. Write actions need a cookie or auth_token.
Error handling
Route each status before exporting downstream rows.
| Status | Action |
|---|---|
400 |
Fix request fields; do not retry unchanged. |
401 |
Replace the API key. |
403 |
Resolve account access or credits. |
429 |
Back off and preserve the cursor. |
5xx |
Retry safe reads with bounded backoff. |
Persist a page cursor only after downstream processing succeeds.
Recipes
Search tweets to Slack
- Schedule the workflow on your reporting cadence.
- Call
POST /twitter/advanced_search/page. - Filter tweets by engagement threshold.
- Send selected tweet text, author, and link to Slack.
Agent handoff to Google Sheets
- HTTP trigger receives MCP handoff JSON.
- Normalize tweet rows.
- Upsert into Sheets by
tweet_id.
Follower page to CRM
- HTTP or scheduled step calls
POST /v3/twitter/users/followers. - Normalize follower rows.
- CRM upserts by
user_id. - Data store retains
next_cursor.
Testing checklist
- Confirm the trigger body is valid JSON.
- Use
tweet_idoruser_idas the dedupe key. - Store
next_cursorin Pipedream data stores for scheduled continuation. - Keep
TWEXAPI_API_KEYin environment variables only. - Never log Bearer tokens in step output.