Skip to main content
POST
/
segments
cURL
curl -X POST https://api.growthbook.io/api/v1/segments \
  -d '{"name":"Annual Subscribers", "datasource":"ds_123abc", "identifierType":"user_id", "type":"SQL", "query":"SELECT plan FROM subscribers WHERE plan = 'annual'"}' \
  -u secret_abc123DEF456:
{
  "segment": {
    "id": "<string>",
    "owner": "<unknown>",
    "datasourceId": "<string>",
    "identifierType": "<string>",
    "name": "<string>",
    "dateCreated": "<string>",
    "dateUpdated": "<string>",
    "description": "<string>",
    "query": "<string>",
    "managedBy": "",
    "type": "SQL",
    "factTableId": "<string>",
    "filters": [
      "<string>"
    ],
    "projects": [
      "<string>"
    ]
  }
}

Documentation Index

Fetch the complete documentation index at: https://growthbook-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Authorizations

Authorization
string
header
required

If using Bearer auth, pass the Secret Key as the token:

curl https://api.growthbook.io/api/v1 \
-H "Authorization: Bearer secret_abc123DEF456"

Body

application/json
name
string
required

Name of the segment

datasourceId
string
required

ID of the datasource this segment belongs to

identifierType
string
required

Type of identifier (user, anonymous, etc.)

type
enum<string>
required

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.

Available options:
SQL,
FACT
owner
any
description
string

Description of the segment

projects
string[]

List of project IDs for projects that can access this segment

managedBy
enum<string>

Where this Segment must be managed from. If not set (empty string), it can be managed from anywhere.

Available options:
,
api
query
string

SQL query that defines the Segment. This is required for SQL segments.

factTableId
string

ID of the fact table this segment belongs to. This is required for FACT segments.

filters
string[]

Optional array of fact table filter ids that can further define the Fact Table based Segment.

Response

200 - application/json

Success

segment
object
required