curl --request POST \
--url https://app.gaintrace.com/api/v1/survey-segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Enterprise decision makers",
"rules": {
"company": {
"logic": "and",
"rules": [
{
"field": "segment",
"operator": "eq",
"value": "enterprise"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "contactRole",
"operator": "is_any_of",
"value": [
"decision_maker",
"executive_sponsor"
]
}
]
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Enterprise decision makers',
rules: {
company: {logic: 'and', rules: [{field: 'segment', operator: 'eq', value: 'enterprise'}]},
person: {
logic: 'and',
rules: [
{
field: 'contactRole',
operator: 'is_any_of',
value: ['decision_maker', 'executive_sponsor']
}
]
}
}
})
};
fetch('https://app.gaintrace.com/api/v1/survey-segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://app.gaintrace.com/api/v1/survey-segments"
payload = {
"name": "Enterprise decision makers",
"rules": {
"company": {
"logic": "and",
"rules": [
{
"field": "segment",
"operator": "eq",
"value": "enterprise"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "contactRole",
"operator": "is_any_of",
"value": ["decision_maker", "executive_sponsor"]
}
]
}
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"company": {
"logic": "and",
"rules": [
{
"field": "<string>",
"operator": "eq",
"value": "<string>",
"value2": "<string>",
"unit": "minutes"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "<string>",
"operator": "eq",
"value": "<string>",
"value2": "<string>",
"unit": "minutes"
}
]
},
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "bad_request",
"message": "Invalid JSON body",
"doc_url": "https://docs.gaintrace.com/errors#bad_request"
}
}{
"error": {
"code": "unauthorized",
"message": "Missing Authorization header",
"doc_url": "https://docs.gaintrace.com/errors#unauthorized"
}
}{
"error": {
"code": "forbidden",
"message": "Insufficient scope: write:companies required",
"doc_url": "https://docs.gaintrace.com/errors#forbidden"
}
}{
"error": {
"code": "unprocessable_entity",
"message": "Request validation failed. name: name is required",
"doc_url": "https://docs.gaintrace.com/errors#unprocessable_entity"
}
}{
"error": {
"code": "rate_limit_exceeded",
"message": "Can't accept more than 60 requests a minute from one API key. Retry in 23 seconds.",
"doc_url": "https://docs.gaintrace.com/errors#rate_limit_exceeded"
}
}{
"error": {
"code": "internal_server_error",
"message": "Something went wrong. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#internal_server_error"
}
}{
"error": {
"code": "service_unavailable",
"message": "We had trouble reaching the database. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#service_unavailable"
}
}{
"error": {
"code": "gateway_timeout",
"message": "The request timed out. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#gateway_timeout"
}
}Create a survey segment
Save a segment of Company and People rules. Use it as a survey’s in-app audience (settings.inApp.targeting.audience.segmentId) or as the audience of an invitation request (segmentId). The name must be unique in the workspace, ignoring case; a name already in use returns 422. A segment needs at least one rule across the two groups. Requires a secret server key (gt_live_). Publishable keys (gt_pub_) return 403.
Scope: write:surveys
curl --request POST \
--url https://app.gaintrace.com/api/v1/survey-segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Enterprise decision makers",
"rules": {
"company": {
"logic": "and",
"rules": [
{
"field": "segment",
"operator": "eq",
"value": "enterprise"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "contactRole",
"operator": "is_any_of",
"value": [
"decision_maker",
"executive_sponsor"
]
}
]
}
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Enterprise decision makers',
rules: {
company: {logic: 'and', rules: [{field: 'segment', operator: 'eq', value: 'enterprise'}]},
person: {
logic: 'and',
rules: [
{
field: 'contactRole',
operator: 'is_any_of',
value: ['decision_maker', 'executive_sponsor']
}
]
}
}
})
};
fetch('https://app.gaintrace.com/api/v1/survey-segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://app.gaintrace.com/api/v1/survey-segments"
payload = {
"name": "Enterprise decision makers",
"rules": {
"company": {
"logic": "and",
"rules": [
{
"field": "segment",
"operator": "eq",
"value": "enterprise"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "contactRole",
"operator": "is_any_of",
"value": ["decision_maker", "executive_sponsor"]
}
]
}
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"company": {
"logic": "and",
"rules": [
{
"field": "<string>",
"operator": "eq",
"value": "<string>",
"value2": "<string>",
"unit": "minutes"
}
]
},
"person": {
"logic": "and",
"rules": [
{
"field": "<string>",
"operator": "eq",
"value": "<string>",
"value2": "<string>",
"unit": "minutes"
}
]
},
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "bad_request",
"message": "Invalid JSON body",
"doc_url": "https://docs.gaintrace.com/errors#bad_request"
}
}{
"error": {
"code": "unauthorized",
"message": "Missing Authorization header",
"doc_url": "https://docs.gaintrace.com/errors#unauthorized"
}
}{
"error": {
"code": "forbidden",
"message": "Insufficient scope: write:companies required",
"doc_url": "https://docs.gaintrace.com/errors#forbidden"
}
}{
"error": {
"code": "unprocessable_entity",
"message": "Request validation failed. name: name is required",
"doc_url": "https://docs.gaintrace.com/errors#unprocessable_entity"
}
}{
"error": {
"code": "rate_limit_exceeded",
"message": "Can't accept more than 60 requests a minute from one API key. Retry in 23 seconds.",
"doc_url": "https://docs.gaintrace.com/errors#rate_limit_exceeded"
}
}{
"error": {
"code": "internal_server_error",
"message": "Something went wrong. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#internal_server_error"
}
}{
"error": {
"code": "service_unavailable",
"message": "We had trouble reaching the database. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#service_unavailable"
}
}{
"error": {
"code": "gateway_timeout",
"message": "The request timed out. Try again in a moment.",
"doc_url": "https://docs.gaintrace.com/errors#gateway_timeout"
}
}Authorizations
Bearer API key. Secret server keys start with gt_live_; client-safe browser keys start with gt_pub_ (write-only, origin-pinned). Create and scope keys in Settings → API Keys.
Body
Unique in the workspace, ignoring case.
1 - 120Who to reach: People who match person, at Companies that match company. An empty rules list in a group matches everyone for that group. A request needs at least one rule across both groups, so nobody is ever invited by accident. Only People with an email address at Companies that aren't archived can match.
Show child attributes
Show child attributes
Response
Segment saved.
Show child attributes
Show child attributes
Was this page helpful?