> ## Documentation Index
> Fetch the complete documentation index at: https://developers.redo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# createSampledSegment

> Create a new static segment holding a random sample of up to `sampleSize` members of a static or dynamic segment. A source with fewer members is copied whole, and an empty source (or a dynamic one with no conditions) gives an empty segment. A dynamic source is sampled from the same periodically refreshed data as its `memberCount`, not live. The source is unchanged, and each call draws a new sample. Returns null if the caller owns no segment with that id. Fails with UNSUPPORTED_SEGMENT_TYPE for persona segments. The call waits for the write and can take over a minute for a large segment, so if it times out, look the segment up by name before retrying.

**Required scopes:** [`segments_write`](https://developers.redo.com/docs/api-reference/v3/reference/scopes#scope-segments_write)

**Store must have one of:** `EMAIL_SMS`

## Arguments

**input** `[CreateSampledSegmentInput!](/docs/api-reference/v3/reference/marketing/create-sampled-segment-input)` *required*

The segment to sample, the sample size and the new name.

**fields**

**name** `String!` *required*

The merchant-facing name of the new segment.

**sampleSize** `Int!` *required*

The most members to sample, 1 to 100000. A segment with fewer members is copied whole.

**segmentId** `ID!` *required*

The `id` (or `legacyId`) of the static or dynamic segment to sample.

## Returns

**createSampledSegment** `[Segment](/docs/api-reference/v3/reference/marketing/segment)`

A group of customers that campaigns and automations send to.

**fields**

**conditions** `[JSON](/docs/api-reference/v3/reference/common/json)`

Dynamic segment condition tree. Null for static and persona segments.

**countsRefreshedAt** `[DateTime](/docs/api-reference/v3/reference/common/date-time)`

When the member counts were last recalculated. They are not live.

**createdAt** `[DateTime!](/docs/api-reference/v3/reference/common/date-time)` *required*

When the segment was created.

**description** `String`

The merchant's description of who this segment is for.

**emailSubscriberCount** `Int`

Members subscribed to email marketing as of `countsRefreshedAt`.

**id** `ID!` *required*

The id of this segment.

**legacyId** `String!` *required*

The segment's legacy Mongo ObjectId (24-char hex) from before the CockroachDB migration.

**memberCount** `Int`

Customers in the segment as of `countsRefreshedAt`. Null until it has first been counted.

**name** `String!` *required*

The merchant-facing name of the segment.

**smsSubscriberCount** `Int`

Members subscribed to SMS marketing as of `countsRefreshedAt`.

**type** `[SegmentType!](/docs/api-reference/v3/reference/marketing/segment-type)` *required*

How membership of this segment is determined.

**updatedAt** `[DateTime!](/docs/api-reference/v3/reference/common/date-time)` *required*

When the segment was last updated.

## Example

```graphql theme={null}
mutation {
  createSampledSegment(input: { ... }) {
    conditions
    countsRefreshedAt
    createdAt
    description
    emailSubscriberCount
    id
    legacyId
    memberCount
    # ...
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.