GrowthBook segments API
Segments used during experiment analysis
Segments used during experiment analysis
openapi: 3.1.0
info:
version: 1.0.0
title: GrowthBook REST AnalyticsExplorations segments API
description: "GrowthBook offers a full REST API for interacting with the application.\n\nRequest data can use either JSON or Form data encoding (with proper `Content-Type` headers). All response bodies are JSON-encoded.\n\nThe API base URL for GrowthBook Cloud is `https://api.growthbook.io/api`. For self-hosted deployments, it is the same as your API_HOST environment variable (defaults to `http://localhost:3100/api`). The rest of these docs will assume you are using GrowthBook Cloud.\n\n## Versioning\n\nEndpoints are versioned by path prefix:\n\n- `/v1/...` — stable, widely-supported endpoints\n- `/v2/...` — updated endpoints with improved shapes (e.g. unified per-rule environment scope for feature flags)\n\nNew integrations should prefer v2 where available.\n\n## Authentication\n\nWe support both the HTTP Basic and Bearer authentication schemes for convenience.\n\nYou first need to generate a new API Key in GrowthBook. Different keys have different permissions:\n\n- **Personal Access Tokens**: These are sensitive and provide the same level of access as the user has to an organization. These can be created by going to `Personal Access Tokens` under the your user menu.\n- **Secret Keys**: These are sensitive and provide the level of access for the role, which currently is either `admin` or `readonly`. Only Admins with the `manageApiKeys` permission can manage Secret Keys on behalf of an organization. These can be created by going to `Settings -> API Keys`\n\nIf using HTTP Basic auth, pass the Secret Key as the username and leave the password blank (when using curl, add `:` at the end of the secret to indicate an empty password)\n\n```bash\ncurl https://api.growthbook.io/api/v1/features \\\n -u secret_abc123DEF456:\n```\n\nIf using Bearer auth, pass the Secret Key as the token:\n\n```bash\ncurl https://api.growthbook.io/api/v1/features \\\n-H \"Authorization: Bearer secret_abc123DEF456\"\n```\n\n## Errors\n\nThe API may return the following error status codes:\n\n- **400** - Bad Request - Often due to a missing required parameter\n- **401** - Unauthorized - No valid API key provided\n- **402** - Request Failed - The parameters are valid, but the request failed\n- **403** - Forbidden - Provided API key does not have the required access\n- **404** - Not Found - Unknown API route or requested resource\n- **429** - Too Many Requests - You exceeded the rate limit of 60 requests per minute. Try again later.\n- **5XX** - Server Error - Something went wrong on GrowthBook's end (these are rare)\n\nThe response body will be a JSON object with the following properties:\n\n- **message** - Information about the error\n"
servers:
- url: https://api.growthbook.io/api
description: GrowthBook Cloud
- url: https://{domain}/api
description: Self-hosted GrowthBook
security:
- bearerAuth: []
- basicAuth: []
tags:
- name: segments
x-displayName: Segments
description: Segments used during experiment analysis
paths:
/v1/segments:
get:
operationId: listSegments
summary: Get all segments
tags:
- segments
parameters:
- $ref: '#/components/parameters/limit'
- $ref: '#/components/parameters/offset'
- $ref: '#/components/parameters/datasourceId'
responses:
'200':
content:
application/json:
schema:
allOf:
- type: object
properties:
segments:
type: array
items:
$ref: '#/components/schemas/Segment'
required:
- segments
additionalProperties: false
- $ref: '#/components/schemas/PaginationFields'
x-codeSamples:
- lang: cURL
source: "curl -X GET 'https://api.growthbook.io/api/v1/segments' \\\n -H 'Authorization: Bearer YOUR_API_KEY'"
post:
operationId: postSegment
summary: Create a single segment
tags:
- segments
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
description: Name of the segment
type: string
owner:
description: The userId or email address of the owner. If an email address is provided, it will be used to look up the userId of the matching organization member. If an ID is provided, it will be validated as existing in the organization.
type: string
description:
description: Description of the segment
type: string
datasourceId:
description: ID of the datasource this segment belongs to
type: string
identifierType:
description: Type of identifier (user, anonymous, etc.)
type: string
projects:
description: List of project IDs for projects that can access this segment
type: array
items:
type: string
managedBy:
description: Where this Segment must be managed from. If not set (empty string), it can be managed from anywhere.
type: string
enum:
- ''
- api
type:
description: GrowthBook supports two types of Segments, SQL and FACT. SQL segments are defined by a SQL query, and FACT segments are defined by a fact table and filters.
type: string
enum:
- SQL
- FACT
query:
description: SQL query that defines the Segment. This is required for SQL segments.
type: string
factTableId:
description: ID of the fact table this segment belongs to. This is required for FACT segments.
type: string
filters:
description: Optional array of fact table filter ids that can further define the Fact Table based Segment.
type: array
items:
type: string
required:
- name
- datasourceId
- identifierType
- type
additionalProperties: false
responses:
'200':
content:
application/json:
schema:
type: object
properties:
segment:
$ref: '#/components/schemas/Segment'
required:
- segment
additionalProperties: false
x-codeSamples:
- lang: cURL
source: "curl -X POST 'https://api.growthbook.io/api/v1/segments' \\\n -H 'Authorization: Bearer YOUR_API_KEY' \\\n -H 'Content-Type: application/json' \\\n -d '{\"name\":\"Annual Subscribers\",\"datasourceId\":\"ds_123abc\",\"identifierType\":\"user_id\",\"type\":\"SQL\",\"query\":\"SELECT plan FROM subscribers WHERE plan = \"}'"
/v1/segments/{id}:
get:
operationId: getSegment
summary: Get a single segment
tags:
- segments
parameters:
- $ref: '#/components/parameters/id'
responses:
'200':
content:
application/json:
schema:
type: object
properties:
segment:
$ref: '#/components/schemas/Segment'
required:
- segment
additionalProperties: false
x-codeSamples:
- lang: cURL
source: "curl -X GET 'https://api.growthbook.io/api/v1/segments/abc123' \\\n -H 'Authorization: Bearer YOUR_API_KEY'"
post:
operationId: updateSegment
summary: Update a single segment
tags:
- segments
parameters:
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
description: Name of the segment
type: string
owner:
description: The userId or email address of the owner. If an email address is provided, it will be used to look up the userId of the matching organization member. If an ID is provided, it will be validated as existing in the organization.
type: string
description:
description: Description of the segment
type: string
datasourceId:
description: ID of the datasource this segment belongs to
type: string
identifierType:
description: Type of identifier (user, anonymous, etc.)
type: string
projects:
description: List of project IDs for projects that can access this segment
type: array
items:
type: string
managedBy:
description: Where this Segment must be managed from. If not set (empty string), it can be managed from anywhere.
type: string
enum:
- ''
- api
type:
description: GrowthBook supports two types of Segments, SQL and FACT. SQL segments are defined by a SQL query, and FACT segments are defined by a fact table and filters.
type: string
enum:
- SQL
- FACT
query:
description: SQL query that defines the Segment. This is required for SQL segments.
type: string
factTableId:
description: ID of the fact table this segment belongs to. This is required for FACT segments.
type: string
filters:
description: Optional array of fact table filter ids that can further define the Fact Table based Segment.
type: array
items:
type: string
additionalProperties: false
responses:
'200':
content:
application/json:
schema:
type: object
properties:
segment:
$ref: '#/components/schemas/Segment'
required:
- segment
additionalProperties: false
x-codeSamples:
- lang: cURL
source: "curl -X POST 'https://api.growthbook.io/api/v1/segments/abc123' \\\n -H 'Authorization: Bearer YOUR_API_KEY' \\\n -H 'Content-Type: application/json' \\\n -d '{\"name\":\"User Region\"}'"
delete:
operationId: deleteSegment
summary: Deletes a single segment
tags:
- segments
parameters:
- $ref: '#/components/parameters/id'
responses:
'200':
content:
application/json:
schema:
type: object
properties:
deletedId:
description: The ID of the deleted segment
example: seg_123abc
type: string
required:
- deletedId
additionalProperties: false
x-codeSamples:
- lang: cURL
source: "curl -X DELETE 'https://api.growthbook.io/api/v1/segments/abc123' \\\n -H 'Authorization: Bearer YOUR_API_KEY'"
components:
parameters:
offset:
name: offset
in: query
description: How many items to skip (use in conjunction with limit for pagination)
schema:
default: 0
description: How many items to skip (use in conjunction with limit for pagination)
type: integer
minimum: 0
id:
name: id
in: path
required: true
description: The id of the requested resource
schema:
description: The id of the requested resource
type: string
limit:
name: limit
in: query
description: The number of items to return
schema:
default: 10
description: The number of items to return
type: integer
minimum: 1
maximum: 100
datasourceId:
name: datasourceId
in: query
description: Filter by Data Source
schema:
description: Filter by Data Source
type: string
schemas:
Segment:
type: object
properties:
id:
type: string
owner:
description: The userId of the owner (or raw owner name/email for legacy records)
type: string
ownerEmail:
description: The email address of the owner, when the owner can be resolved to a known user.
type: string
datasourceId:
type: string
identifierType:
type: string
name:
type: string
description:
type: string
query:
type: string
dateCreated:
type: string
dateUpdated:
type: string
managedBy:
description: Where this segment must be managed from. If not set (empty string), it can be managed from anywhere.
type: string
enum:
- ''
- api
- config
type:
type: string
enum:
- SQL
- FACT
factTableId:
type: string
filters:
type: array
items:
type: string
projects:
type: array
items:
type: string
required:
- id
- owner
- datasourceId
- identifierType
- name
- dateCreated
- dateUpdated
additionalProperties: false
PaginationFields:
type: object
properties:
limit:
type: integer
offset:
type: integer
count:
type: integer
total:
type: integer
hasMore:
type: boolean
nextOffset:
anyOf:
- type: integer
- type: 'null'
required:
- limit
- offset
- count
- total
- hasMore
- nextOffset
additionalProperties: false
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: 'If using Bearer auth, pass the Secret Key as the token:
```bash
curl https://api.growthbook.io/api/v1/features -H "Authorization: Bearer secret_abc123DEF456"
```
'
basicAuth:
type: http
scheme: basic
description: 'If using HTTP Basic auth, pass the Secret Key as the username and leave the password blank:
```bash
curl https://api.growthbook.io/api/v1/features -u secret_abc123DEF456:
# The ":" at the end stops curl from asking for a password
```
'
x-tagGroups:
- name: Endpoints
tags:
- projects
- environments
- features-v2
- feature-revisions-v2
- features
- feature-revisions
- ramp-schedules
- data-sources
- fact-tables
- fact-metrics
- metrics
- experiments
- namespaces
- snapshots
- dimensions
- segments
- sdk-connections
- visual-changesets
- saved-groups
- organizations
- members
- code-references
- archetypes
- queries
- settings
- attributes
- usage
- Dashboards
- CustomFields
- MetricGroups
- Teams
- ExperimentTemplates
- AnalyticsExplorations
- RampScheduleTemplates
- name: Models
tags:
- AnalyticsExploration_model
- Archetype_model
- Attribute_model
- CodeRef_model
- CustomField_model
- Dashboard_model
- DataSource_model
- Dimension_model
- Environment_model
- Experiment_model
- ExperimentAnalysisSettings_model
- ExperimentDecisionFrameworkSettings_model
- ExperimentMetric_model
- ExperimentMetricOverrideEntry_model
- ExperimentResults_model
- ExperimentSnapshot_model
- ExperimentTemplate_model
- ExperimentWithEnhancedStatus_model
- FactMetric_model
- FactTable_model
- FactTableColumn_model
- FactTableFilter_model
- Feature_model
- FeatureBaseRule_model
- FeatureDefinition_model
- FeatureEnvironment_model
- FeatureEnvironmentV2_model
- FeatureExperimentRefRule_model
- FeatureExperimentRule_model
- FeatureForceRule_model
- FeatureRevision_model
- FeatureRevisionV2_model
- FeatureRolloutRule_model
- FeatureRule_model
- FeatureRuleV2_model
- FeatureSafeRolloutRule_model
- FeatureV2_model
- FeatureWithRevisions_model
- FeatureWithRevisionsV2_model
- InformationSchema_model
- InformationSchemaTable_model
- LookbackOverride_model
- Member_model
- Metric_model
- MetricAnalysis_model
- MetricGroup_model
- MetricUsage_model
- Namespace_model
- NamespaceExperimentMember_model
- Organization_model
- PaginationFields_model
- Project_model
- Query_model
- RampSchedule_model
- RampScheduleTemplate_model
- SavedGroup_model
- ScheduleRule_model
- SdkConnection_model
- Segment_model
- Settings_model
- Team_model
- VisualChange_model
- VisualChangeset_model