> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/create-segment.md). Agents can also search and read this documentation through its [MCP server](https://user.netmera.com/netmera-developer-guide/~gitbook/mcp).

# Create Segment

Creates a standard (condition-based) segment. Segments created through the REST API appear in the panel, with their Targeting Rules filled from the request.

#### Capabilities

* **Profile attribute conditions** — Match users by profile attribute values in `profile`.
* **Tag conditions** — Match users by tag in `tags`.
* **Behavior and response conditions** — Match users by behavior (`behaviors`, `behaviorAggregations`) or campaign response (`response`).
* **Push permission** — Match users by push permission in `pushEnabled`.
* **Condition trees** — Combine conditions with `AND` and `OR` in `targetJson`.

#### How it works

1. Send the segment definition. The body is the same as the one the panel uses to save a segment, and the same rules apply.
2. The segment is saved with `segmentStatus` `WAITING_CALCULATE` and calculated asynchronously.
3. Follow the status with `getSegment`. Wait for `READY` before sending to the segment.

<details>

<summary>Notes</summary>

* The segment name must be unique in the application.
* At least one condition is required.
* The segment limit of the application package applies.
* The server sets `createdBy` to `REST`.
* The status, the user count, the segment type and the business unit are not read from the request.

</details>

```json
{"openapi":"3.1.0","info":{"title":"Netmera REST API","version":"3.0"},"tags":[{"name":"Segments and Targeting","description":"List and manage segments, read their users, and count how many users a target reaches before you\nsend.\n\n<table data-view=\"cards\"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type=\"content-ref\"></th></tr></thead><tbody><tr><td><strong>List Segments</strong></td><td><code>GET</code> Lists the segments defined in the panel.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/list-segments\">List Segments</a></td></tr><tr><td><strong>Get Segment</strong></td><td><code>GET</code> Returns the status and the user count of a segment.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/get-segment\">Get Segment</a></td></tr><tr><td><strong>List Segment Users</strong></td><td><code>GET</code> Returns the users in a segment, one page at a time.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/list-segment-users\">List Segment Users</a></td></tr><tr><td><strong>Create Segment</strong></td><td><code>POST</code> Creates a standard (condition-based) segment.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/create-segment\">Create Segment</a></td></tr><tr><td><strong>Update Segment</strong></td><td><code>POST</code> Replaces the conditions of a segment and calculates it again.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/update-segment\">Update Segment</a></td></tr><tr><td><strong>Change Segment Status</strong></td><td><code>POST</code> Deletes a segment, or reopens a deleted one.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/change-segment-status\">Change Segment Status</a></td></tr><tr><td><strong>Count Targeted Users</strong></td><td><code>POST</code> Returns the number of unique users who match a targeting query.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/count-targeted-users\">Count Targeted Users</a></td></tr><tr><td><strong>Count Users per Attribute Value</strong></td><td><code>POST</code> Returns the distinct user count for every value of one profile or installation attribute in a single request.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/count-users-per-attribute-value\">Count Users per Attribute Value</a></td></tr><tr><td><strong>Count Users with Push Permission</strong></td><td><code>GET</code> Returns the number of users in your application who currently have push permission.</td><td><a href=\"https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/count-users-with-push-permission\">Count Users with Push Permission</a></td></tr></tbody></table>\n"}],"servers":[{"url":"https://restapi.netmera.com","description":"Netmera REST API"}],"security":[{"REST-API-key":[]}],"components":{"securitySchemes":{"REST-API-key":{"type":"apiKey","in":"header","name":"X-netmera-api-key","description":"REST API key. Available in the Netmera Panel under Developers > API.\n"}},"schemas":{"SegmentRequest":{"type":"object","description":"Segment definition used by `createSegment` and `updateSegment`, the same body the panel sends when\nit saves a segment. Send at least one condition, as separate condition objects (`profile`, `tags`,\n`behaviors`, `response`, `pushEnabled`) or as a condition tree in `targetJson`.\n","required":["segment"],"properties":{"segment":{"type":"object","required":["segmentName"],"properties":{"segmentName":{"type":"string","description":"Segment name. Must be unique in the application."},"segmentId":{"type":"integer","description":"ID of the segment to update. Required by `updateSegment` only."},"segmentDescription":{"type":"string","description":"Segment description."},"tagConditionType":{"type":"string","description":"`AND` or `OR`. How the tag condition joins the conditions before it.\n"},"profileConditionType":{"type":"string","description":"`AND` or `OR`. How the profile condition joins the conditions before it.\n"},"responseConditionType":{"type":"string","description":"`AND` or `OR`. How the campaign response condition joins the conditions before\nit.\n"},"behaviorConditionType":{"type":"string","description":"`AND` or `OR`. How the behavior condition joins the conditions before it.\n"}}},"profile":{"type":"object","description":"Profile attribute condition; `expression.code` is the attribute code listed in the panel under\n**Developers > Profile Attributes > Code**. The examples use the `CONTAINS` operator.\n","properties":{"type":{"type":"string","description":"`PROFILE`."},"logic":{"type":"string","description":"`AND` or `OR`."},"expression":{"type":"object","properties":{"code":{"type":"string"},"operator":{"type":"string"},"values":{"type":"array","items":{"type":"string"}}}}},"additionalProperties":true},"tags":{"type":"object","description":"Tag condition. `code` is the ID of the tag.","properties":{"type":{"type":"string","description":"`TAG`."},"logic":{"type":"string","description":"`AND` or `OR`."},"code":{"type":"string"}},"additionalProperties":true},"behaviors":{"type":"object","description":"Behavior condition.","additionalProperties":true},"behaviorAggregations":{"type":"object","description":"Aggregated behavior condition.","additionalProperties":true},"response":{"type":"object","description":"Campaign response condition.","additionalProperties":true},"pushEnabled":{"description":"Push permission condition."},"targetJson":{"type":"object","description":"Condition tree of the panel, for segments that combine conditions with `AND` and `OR`. A group\nhas `type` `GROUP`, a `logic` that joins its `conditions`, and each condition is a channel\npermission (`CHANNEL`), a profile attribute (`PROFILE`) or a nested group.\n","properties":{"id":{"type":"string"},"type":{"type":"string"},"logic":{"type":"string"},"conditions":{"type":"array","items":{"type":"object","additionalProperties":true}}},"additionalProperties":true},"group":{"type":"object","description":"Condition tree in the format of the earlier panel.","additionalProperties":true},"timeZone":{"type":"string","description":"IANA time zone, for example `Europe/Istanbul`, used for relative dates in behavior\nconditions such as \"today\" or \"last 7 days\". When it is not sent, the time zone of\nthe application is used.\n"}}},"SegmentResponse":{"type":"object","required":["id","name","status","segmentStatus"],"properties":{"id":{"type":"integer","description":"Segment ID."},"name":{"type":"string","description":"Segment name."},"status":{"type":"string","description":"`ACTIVE` or `DELETED`."},"segmentStatus":{"type":"string","description":"Calculation status. `WAITING_CALCULATE` while the segment is calculated, `READY`\nwhen it can be used as a target, `WAITING_DELETED` after a delete.\n"},"userCount":{"type":["integer","null"],"description":"Number of users in the segment. `null` until the first calculation finishes.\n"},"createdBy":{"type":["string","null"],"description":"`REST` for segments created through the REST API."}}},"NetmeraError":{"type":"object","description":"Standard Netmera error body.","required":["code","error"],"properties":{"code":{"type":"integer","description":"Netmera error code. See the error table in the API description."},"error":{"type":"string","description":"Human readable error message."}}}},"responses":{"InvalidApiKey":{"description":"The `X-netmera-api-key` header is missing or the key is not valid.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NetmeraError"}}}},"IpNotAllowed":{"description":"The application restricts REST calls to a list of allowed IP addresses and the caller's\nIP is not on it. The check runs after the API key is validated and before the request\nbody and parameters are validated, so a restricted application returns this error even\nfor a malformed request.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NetmeraError"}}}}}},"paths":{"/rest/3.0/createSegment":{"post":{"operationId":"createSegment","tags":["Segments and Targeting"],"summary":"Create Segment","description":"Creates a standard (condition-based) segment. Segments created through the REST API appear in the\npanel, with their Targeting Rules filled from the request.\n\n### Capabilities\n\n- **Profile attribute conditions** — Match users by profile attribute values in `profile`.\n- **Tag conditions** — Match users by tag in `tags`.\n- **Behavior and response conditions** — Match users by behavior (`behaviors`,\n  `behaviorAggregations`) or campaign response (`response`).\n- **Push permission** — Match users by push permission in `pushEnabled`.\n- **Condition trees** — Combine conditions with `AND` and `OR` in `targetJson`.\n\n### How it works\n\n1. Send the segment definition. The body is the same as the one the panel uses to save a segment,\n   and the same rules apply.\n2. The segment is saved with `segmentStatus` `WAITING_CALCULATE` and calculated asynchronously.\n3. Follow the status with `getSegment`. Wait for `READY` before sending to the segment.\n\n<details>\n\n<summary>Notes</summary>\n\n- The segment name must be unique in the application.\n- At least one condition is required.\n- The segment limit of the application package applies.\n- The server sets `createdBy` to `REST`.\n- The status, the user count, the segment type and the business unit are not read from the request.\n\n</details>\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SegmentRequest"}}}},"responses":{"200":{"description":"The segment was saved and its calculation started. `segmentStatus` is\n`WAITING_CALCULATE` and `userCount` is `null` until the calculation finishes.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SegmentResponse"}}}},"400":{"description":"The segment was not saved:\n\n- A segment with the same name exists (5025, Segment name must be unique).\n- The segment limit of the application package is exceeded (5022, Service usage\n  quota is exceeded).\n- The request has no condition (\"Empty criteria\").\n"},"401":{"$ref":"#/components/responses/InvalidApiKey"},"403":{"$ref":"#/components/responses/IpNotAllowed"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://user.netmera.com/netmera-developer-guide/api-documentation/api-reference/segments-and-targeting/create-segment.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
