GET
/segments/List all user segments
You can return a list with all of your users’ segments. Use a returned URL to list all users added to the segment.
Request
- CURL
- JavaScript
- PHP
- Python
curl -X GET -H "Authorization: Token <your_64_char_api_key>"
-H "Accept: */*; version=2"
"https://<your_app_subdomain>.user.com/api/public/segments/"
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://<your_app_subdomain>.user.com/api/public/segments/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("accept", "*/*; version=2");
xhr.send(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/segments/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: */*; version=2",
"authorization: Token <your_64_char_api_key>"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import http.client
conn = http.client.HTTPSConnection("<your_app_subdomain>.user.com")
headers = { 'authorization': "Token <your_64_char_api_key>", "Accept": "*/*; version=2" }
conn.request("GET", "/api/public/segments/", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Response
{
"previous": null,
"results": [
{
"name": "Active",
"description": "Users who have visited your website at least once in the last 30 days.",
"users": "https://<your_app_subdomain>.user.com/api/public/segments/1033/users/",
"id": 1033,
"object_count": 100,
"too_heavy": false,
"update_interval": 240,
"last_counted": "2024-10-11T10:12:32.661576Z",
"updated_at": "2024-10-11T10:12:32.661848Z"
},
{
"name": "New",
"description": "Users who have visited your website for the first time in the last 24 hours.",
"users": "https://<your_app_subdomain>.user.com/api/public/segments/1034/users/",
"id": 1034,
"object_count": 100,
"too_heavy": false,
"update_interval": 240,
"last_counted": "2024-10-11T10:12:32.661576Z",
"updated_at": "2024-10-11T10:12:32.661848Z"
},
{
"name": "New with email",
"description": "Users who first visited your website in the last 24 hours and have provided an email address.",
"users": "https://<your_app_subdomain>.user.com/api/public/segments/1037/users/",
"id": 1037,
"object_count": 100,
"too_heavy": false,
"update_interval": 240,
"last_counted": "2024-10-11T10:12:32.661576Z",
"updated_at": "2024-10-11T10:12:32.661848Z"
},
{
"name": "With email",
"description": "Users whose email address you have.",
"users": "https://<your_app_subdomain>.user.com/api/public/segments/1036/users/",
"id": 1036,
"object_count": 100,
"too_heavy": false,
"update_interval": 240,
"last_counted": "2024-10-11T10:12:32.661576Z",
"updated_at": "2024-10-11T10:12:32.661848Z"
},
{
"name": "Slipping away",
"description": "Users who have not visited your page within the last 30 days.",
"users": "https://<your_app_subdomain>.user.com/api/public/segments/1035/users/",
"id": 1035,
"object_count": 100,
"too_heavy": false,
"update_interval": 240,
"last_counted": "2024-10-11T10:12:32.661576Z",
"updated_at": "2024-10-11T10:12:32.661848Z"
}
],
"next": null,
"count": 5
}