# Segment on boxd

> Twilio Segment is a customer data platform that helps businesses collect, clean, and control their customer data.

- Page: https://boxd.sh/integrations/segment/
- CLI: `run segment` (17 commands, 10 marked common)
- SDK: `import { segment } from "@boxd/run"`; every parameter and response type is at `@boxd/run/segment`
- Triggers: none
- Connect: `run auth segment` (API key), or https://app.boxd.sh/integrations/detail/segment
- All integrations: https://boxd.sh/integrations/ (Markdown: https://boxd.sh/integrations/index.md)

## From the shell

```sh
run auth segment      # once: prints a link to connect your account
run segment           # list its commands
run segment screen --help
```

Parameters are flags (`--flag value`); object and array parameters take a JSON string. Output is YAML, or JSON with `--json`. Calls use your own connection; `--scope <name>` uses a connection shared with your team.

## From a script

```ts
import { every, segment } from "@boxd/run";

every("1 hour", async () => {
  const result = await segment.screen({});
  console.log(result);
});
```

Run it with `run segment.run.ts`. Segment has no triggers; `every()` polls on a schedule, keeps the script running as a job, and wakes the machine when it is due.

## Commands

Required flags are listed; `run segment <command> --help` lists the optional ones. "common" marks what `run segment` shows without `--all`.

| Command | SDK method | Required flags | Optional | Description |
|---|---|---|---|---|
| `add-labels-to-source` | `segment.addLabelsToSource()` | `--labels` `--sourceId` | 0 | Add existing labels to a Source |
| `alias` ·common | `segment.alias()` | `--previousId` | 5 | Alias a previous user ID to a new user ID |
| `batch` ·common | `segment.batch()` | `--batch` | 3 | Send multiple analytics calls in a single batch request |
| `delete-source` ·common | `segment.deleteSource()` | `--sourceId` | 0 | Delete a Segment Source |
| `get-daily-per-source-api-calls-usage` | `segment.getDailyPerSourceApiCallsUsage()` | `--period` | 1 | Fetch daily API call counts per source for a given period |
| `get-destination` | `segment.getDestination()` | `--destinationId` | 0 | Retrieve a Destination by ID |
| `group` ·common | `segment.group()` | `--groupId` | 7 | Associate an identified user with a group via Segment HTTP Tracking API |
| `identify` ·common | `segment.identify()` | — | 8 | Identify a user and set/update traits via Segment HTTP Tracking API |
| `import-historical-data` ·common | `segment.importHistoricalData()` | `--batch` | 2 | Import historical data in bulk with support for historical timestamps |
| `list-connected-warehouses-from-source` | `segment.listConnectedWarehousesFromSource()` | `--pagination` `--sourceId` | 0 | List warehouses connected to a Source |
| `list-delivery-metrics-summary-from-destination` | `segment.listDeliveryMetricsSummaryFromDestination()` | `--destinationId` `--sourceId` | 3 | Get an event delivery metrics summary from a Destination |
| `list-schema-settings-in-source` | `segment.listSchemaSettingsInSource()` | `--sourceId` | 0 | Retrieve schema configuration settings for a Source |
| `page` ·common | `segment.page()` | — | 9 | Record a page view via Segment HTTP Tracking API |
| `remove-source-write-key` | `segment.removeSourceWriteKey()` | `--sourceId` `--writeKey` | 0 | Remove a write key from a Source |
| `screen` ·common | `segment.screen()` | — | 8 | Record a mobile app screen view |
| `track` ·common | `segment.track()` | `--event` | 7 | Record a custom user event via Segment HTTP Tracking API |
| `update-source` ·common | `segment.updateSource()` | `--sourceId` | 4 | Update a Source's metadata and settings |

## Docs

- [run CLI](https://docs.boxd.sh/cli/run): Call connected integrations from the shell, connect new ones, and run automations.
- [Quickstart](https://docs.boxd.sh/guides/integrations/quickstart): Connect an integration, call it from the shell, and turn a script into an automation.
- [Connections](https://docs.boxd.sh/guides/integrations/connections): Connect an account once, for yourself or for your whole organization.
- [Scripts](https://docs.boxd.sh/guides/automations/scripts): Typed integrations, triggers, schedules and state in a .run.ts file.
- [Jobs](https://docs.boxd.sh/guides/automations/jobs): How a script becomes a background job: states, retries, sleep and wake.
- [Beyond the catalog](https://docs.boxd.sh/guides/automations/beyond-the-catalog): Reach your own APIs, databases and cloud accounts from a script.
