Create a new segment
curl --request POST \
--url https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Example segment",
"query": {
"logic": "AND",
"criteria": [
{
"logic": "OR",
"criteria": [
{
"field": "paxadults",
"operator": ">",
"value": "3"
},
{
"field": "farecode",
"operator": "=",
"value": "FOO"
}
]
}
]
}
}
'const url = 'https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new';
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Example segment',
query: {
logic: 'AND',
criteria: [
{
logic: 'OR',
criteria: [
{field: 'paxadults', operator: '>', value: '3'},
{field: 'farecode', operator: '=', value: 'FOO'}
]
}
]
}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new"
payload = {
"name": "Example segment",
"query": {
"logic": "AND",
"criteria": [
{
"logic": "OR",
"criteria": [
{
"field": "paxadults",
"operator": ">",
"value": "3"
},
{
"field": "farecode",
"operator": "=",
"value": "FOO"
}
]
}
]
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Example segment',
'query' => [
'logic' => 'AND',
'criteria' => [
[
'logic' => 'OR',
'criteria' => [
[
'field' => 'paxadults',
'operator' => '>',
'value' => '3'
],
[
'field' => 'farecode',
'operator' => '=',
'value' => 'FOO'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}using RestSharp;
var options = new RestClientOptions("https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Bearer <token>");
request.AddJsonBody("{\n \"name\": \"Example segment\",\n \"query\": {\n \"logic\": \"AND\",\n \"criteria\": [\n {\n \"logic\": \"OR\",\n \"criteria\": [\n {\n \"field\": \"paxadults\",\n \"operator\": \">\",\n \"value\": \"3\"\n },\n {\n \"field\": \"farecode\",\n \"operator\": \"=\",\n \"value\": \"FOO\"\n }\n ]\n }\n ]\n }\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
HttpResponse<String> response = Unirest.post("https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Example segment\",\n \"query\": {\n \"logic\": \"AND\",\n \"criteria\": [\n {\n \"logic\": \"OR\",\n \"criteria\": [\n {\n \"field\": \"paxadults\",\n \"operator\": \">\",\n \"value\": \"3\"\n },\n {\n \"field\": \"farecode\",\n \"operator\": \"=\",\n \"value\": \"FOO\"\n }\n ]\n }\n ]\n }\n}")
.asString();Segments
Create a segment
Save a set of search criteria under a name
POST
/
api
/
guestprofile
/
entities
/
{entity_id}
/
segments
/
new
Create a new segment
curl --request POST \
--url https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Example segment",
"query": {
"logic": "AND",
"criteria": [
{
"logic": "OR",
"criteria": [
{
"field": "paxadults",
"operator": ">",
"value": "3"
},
{
"field": "farecode",
"operator": "=",
"value": "FOO"
}
]
}
]
}
}
'const url = 'https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new';
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Example segment',
query: {
logic: 'AND',
criteria: [
{
logic: 'OR',
criteria: [
{field: 'paxadults', operator: '>', value: '3'},
{field: 'farecode', operator: '=', value: 'FOO'}
]
}
]
}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new"
payload = {
"name": "Example segment",
"query": {
"logic": "AND",
"criteria": [
{
"logic": "OR",
"criteria": [
{
"field": "paxadults",
"operator": ">",
"value": "3"
},
{
"field": "farecode",
"operator": "=",
"value": "FOO"
}
]
}
]
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Example segment',
'query' => [
'logic' => 'AND',
'criteria' => [
[
'logic' => 'OR',
'criteria' => [
[
'field' => 'paxadults',
'operator' => '>',
'value' => '3'
],
[
'field' => 'farecode',
'operator' => '=',
'value' => 'FOO'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}using RestSharp;
var options = new RestClientOptions("https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Bearer <token>");
request.AddJsonBody("{\n \"name\": \"Example segment\",\n \"query\": {\n \"logic\": \"AND\",\n \"criteria\": [\n {\n \"logic\": \"OR\",\n \"criteria\": [\n {\n \"field\": \"paxadults\",\n \"operator\": \">\",\n \"value\": \"3\"\n },\n {\n \"field\": \"farecode\",\n \"operator\": \"=\",\n \"value\": \"FOO\"\n }\n ]\n }\n ]\n }\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
HttpResponse<String> response = Unirest.post("https://{apiBaseUrl}/api/guestprofile/entities/{entity_id}/segments/new")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Example segment\",\n \"query\": {\n \"logic\": \"AND\",\n \"criteria\": [\n {\n \"logic\": \"OR\",\n \"criteria\": [\n {\n \"field\": \"paxadults\",\n \"operator\": \">\",\n \"value\": \"3\"\n },\n {\n \"field\": \"farecode\",\n \"operator\": \"=\",\n \"value\": \"FOO\"\n }\n ]\n }\n ]\n }\n}")
.asString();The response carries no body. The
location header holds the path of the new segment, and its last path segment is the identifier to store on your side.Was this page helpful?