CONNECT APP
Build with Segment
Data Analytics
- API key
MCP
Give your agent Segment tools
Every Segment action is exposed as an MCP tool on Pipedream's remote server. Point a client at it with your end user's ID and Connect resolves that user's Segment account for each tool call — you store no tokens.
// accessToken: mint a short-lived token with the Connect SDK — see the MCP guide
const transport = new StreamableHTTPClientTransport(
new URL("https://remote.mcp.pipedream.net/v3"),
{
requestInit: {
headers: {
Authorization: `Bearer ${accessToken}`,
"x-pd-project-id": "{project_id}",
"x-pd-environment": "production",
"x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
"x-pd-app-slug": "segment",
},
},
},
)
const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)
const { tools } = await mcp.listTools()
// e.g. run Associate an identified user with a group:
const result = await mcp.callTool({
name: "segment-group",
arguments: {
anonymousId: "Anonymous ID",
context: "Context",
},
})# access_token: mint a short-lived token with the Connect SDK — see the MCP guide
headers = {
"Authorization": f"Bearer {access_token}",
"x-pd-project-id": "{project_id}",
"x-pd-environment": "production",
"x-pd-external-user-id": "{external_user_id}", # any stable ID for this user in your system
"x-pd-app-slug": "segment",
}
async with streamablehttp_client("https://remote.mcp.pipedream.net/v3", headers=headers) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
# e.g. run Associate an identified user with a group:
result = await session.call_tool("segment-group", {
"anonymousId": "Anonymous ID",
"context": "Context",
})API PROXY
Call the Segment API directly
For an endpoint with no pre-built tool, the Connect proxy forwards your request to the Segment API with the connected user's credentials attached. You store no tokens and write no refresh logic.
const resp = await pd.proxy.get({
externalUserId: "{external_user_id}", // any stable ID for this user in your system
accountId: "apn_xxxxxxx",
url: "https://api.segment.io/v1/track",
})
// Any allowed Segment endpoint works here. Pipedream attaches the
// connected account's credentials to the outgoing request.# The path segment is the target URL, URL-safe base64 encoded:
# https://api.segment.io/v1/track
curl "https://api.pipedream.com/v1/connect/{project_id}/proxy/aHR0cHM6Ly9hcGkuc2VnbWVudC5pby92MS90cmFjaw?external_user_id={external_user_id}&account_id=apn_xxxxxxx" \
-H "Authorization: Bearer {access_token}" \
-H "x-pd-environment: production"SDK
Run Segment actions from your backend
Connect a user's Segment account once, then run Associate an identified user with a group on their behalf from your own code — TypeScript, Python, or plain HTTP.
import { PipedreamClient } from "@pipedream/sdk"
const pd = new PipedreamClient({
projectId: process.env.PIPEDREAM_PROJECT_ID!,
clientId: process.env.PIPEDREAM_CLIENT_ID!,
clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
projectEnvironment: "production",
})
const result = await pd.actions.run({
id: "segment-group",
externalUserId: "{external_user_id}", // any stable ID for this user in your system
configuredProps: {
segment: { authProvisionId: "apn_xxxxxxx" },
anonymousId: "Anonymous ID",
context: "Context",
},
})from pipedream import Pipedream
pd = Pipedream(
client_id="{oauth_client_id}",
client_secret="{oauth_client_secret}",
project_id="{project_id}",
project_environment="production",
)
result = pd.actions.run(
id="segment-group",
external_user_id="{external_user_id}", # any stable ID for this user in your system
configured_props={
"segment": {"authProvisionId": "apn_xxxxxxx"},
"anonymousId": "Anonymous ID",
"context": "Context",
},
)curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
-H "Content-Type: application/json" \
-H "X-PD-Environment: production" \
-H "Authorization: Bearer {access_token}" \
-d '{
"external_user_id": "{external_user_id}",
"id": "segment-group",
"configured_props": {
"segment": { "authProvisionId": "apn_xxxxxxx" },
"anonymousId": "Anonymous ID",
"context": "Context"
}
}'TOOLS
Segment actions
On-demand operations your product or agent can configure and run on behalf of a connected user.
-
Associate an identified user with a group
actionGroup lets you associate an identified user with a group (note requires userId or anonymousId). See the docs hereWritev0.2.6 -
Associate one identity with another
actionAlias is how you associate one identity with another. See the docs hereWritev0.1.5 -
Identify a user, tie them to their actions and record traits about them
actionIdentify lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about them (note requires userId or anonymousId). See the docs hereWritev0.2.7 -
List Workspace Options
actionRetrieves available options for the Workspace field.Read-onlyv0.0.1 -
Record page views on your website
actionThe page method lets you record page views on your website, along with optional extra information about the page being viewed (note requires userId or anonymousId). See the docs hereWritev0.2.6 -
Record whenever a user sees a screen
actionThe screen method let you record whenever a user sees a screen of your mobile app (note requires userId or anonymousId). See the docs hereWritev0.1.6 -
Track actions your users perform
actionTrack lets you record the actions your users perform (note requires userId or anonymousId). See the docs hereWritev0.3.6
EVENTS
Segment triggers
Event sources your backend can deploy for users and receive through a webhook.
- App slug
- segment
- Authentication
- API key
- Categories
- Data Analytics
- Actions
- 7
- Triggers
- 1
- API proxy
- Available