# Get Event Segmentation — Amplitude

> Query event segmentation data (counts, uniques, and other metrics) for one or more events over a date range from the Amplitude Dashboard REST API. Use this to analyze how an event trends over time, optionally broken down by user…

- Key: `amplitude-get-event-segmentation`
- Type: Action (Read-only)
- Version: 0.0.2
- App: Amplitude (`amplitude`) — https://pipedream.com/apps/amplitude.md
- This page (HTML): https://pipedream.com/apps/amplitude/actions/get-event-segmentation
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/amplitude/actions/get-event-segmentation/get-event-segmentation.mjs

## Description

Query event segmentation data (counts, uniques, and other metrics) for one or more events over a date range from the Amplitude Dashboard REST API. Use this to analyze how an event trends over time, optionally broken down by user properties. Example: call with `event={"event_type":"Purchase"}`, `startDate="20240706"`, `endDate="20240805"`, `metric="uniques"` -> returns `{data: {xValues: ["2024-07-06", ...], series: [[42, 51, ...]]}}` (one value per day per requested series). [See the documentation](https://amplitude.com/docs/apis/analytics/dashboard-rest#event-segmentation).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `event` | `string` | Yes | A single JSON-encoded event definition (the e param). event_type is required; filters and group_by are optional. Use a real event name from your project (e.g. Purchase, Sign Up), or Amplitude's built-in _active/_new events to query overall activity. Example: {"event_type":"_active"} (Amplitude's built-in "any active event" — do NOT use the literal string "Any Active Event", which is Amplitude UI label text, not a valid event_type value, and returns a 400). |
| `startDate` | `string` | Yes | Start date, inclusive, in YYYYMMDD format (the start param). Example: 20240706. |
| `endDate` | `string` | Yes | End date, inclusive, in YYYYMMDD format (the end param). Example: 20240805. |
| `metric` | `string` | No | Metric to compute (the m param). One of: uniques, totals, pct_dau, average, histogram, sums, value_avg, formula. Defaults to uniques. |
| `interval` | `integer` | No | Time interval (the i param). One of -300000 (realtime), -3600000 (hourly), 1 (daily), 7 (weekly), 30 (monthly). Defaults to 1. |
| `segmentDefinitions` | `string` | No | JSON-encoded array of segment definitions (the s param). Example: [{"prop":"country","op":"is","values":["US"]}]. |
| `groupBy` | `string` | No | A user or event property name to group results by (the g param). |
| `groupBy2` | `string` | No | A second property name to group results by (the g2 param). Only used together with Group By. |
| `secondEvent` | `string` | No | A second JSON-encoded event definition (the e2 param) for a derived/comparison metric. Example: {"event_type":"Purchase"}. |
| `limit` | `integer` | No | Maximum number of grouped values to return (the limit param). Min 1, max 1000. Defaults to 100. Amplitude has no cursor for this endpoint — values beyond this cap are silently dropped by the API, not just this tool. If more than limit distinct group-by values may exist, raise this toward 1000 or narrow with Segment Definitions/Group By. |
| `formula` | `string` | No | Custom formula metric expression (the formula param). Required if Metric is set to formula. Example: UNIQUES(A)/UNIQUES(B). |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
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 accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_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": "amplitude",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "amplitude-get-event-segmentation",
  arguments: {
    event: "Event",
    startDate: "Start Date",
  },
})
```

**TypeScript**

```ts
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: "amplitude-get-event-segmentation",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    amplitude: { authProvisionId: "apn_xxxxxxx" },
    event: "Event",
    startDate: "Start Date",
  },
})

console.log(result)
```

**cURL**

```bash
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": "amplitude-get-event-segmentation",
    "configured_props": {
      "amplitude": { "authProvisionId": "apn_xxxxxxx" },
      "event": "Event",
      "startDate": "Start Date"
    }
  }'
```

---

- App: https://pipedream.com/apps/amplitude.md · All apps: https://pipedream.com/apps
