Segments
Créer un segment
Les conditions sont validées comme dans le constructeur de l’interface : un type ou un opérateur inconnu est refusé avec le chemin de la règle fautive.
POST
/
api
/
v1
/
lists
/
{list}
/
segments
Créer un segment
curl --request POST \
--url https://{host}/api/v1/lists/{list}/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Anglophones actifs",
"conditions": {
"operator": "and",
"rules": [
{
"type": "language",
"operator": "equals",
"value": "en"
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 90
}
]
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Anglophones actifs',
conditions: {
operator: 'and',
rules: [
{type: 'language', operator: 'equals', value: 'en'},
{type: 'engagement', operator: 'active_within_days', value: 90}
]
}
})
};
fetch('https://{host}/api/v1/lists/{list}/segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{host}/api/v1/lists/{list}/segments",
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' => 'Anglophones actifs',
'conditions' => [
'operator' => 'and',
'rules' => [
[
'type' => 'language',
'operator' => 'equals',
'value' => 'en'
],
[
'type' => 'engagement',
'operator' => 'active_within_days',
'value' => 90
]
]
]
]),
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;
}import requests
url = "https://{host}/api/v1/lists/{list}/segments"
payload = {
"name": "Anglophones actifs",
"conditions": {
"operator": "and",
"rules": [
{
"type": "language",
"operator": "equals",
"value": "en"
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 90
}
]
}
}
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": "Clients VIP actifs",
"list": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"conditions": {
"operator": "and",
"rules": [
{
"type": "tags",
"operator": "has_any",
"value": [
"vip"
]
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 60
}
]
},
"subscribers_count": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"message": "Unauthenticated."
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "Le champ email doit être une adresse e-mail valide.",
"errors": {}
}Autorisations
Jeton d'API. Aptitude « read » : routes GET seulement. « read + write » : toutes les routes.
En-têtes
Rejouez une écriture sans risque : la même clé rend la première réponse pendant 24 heures (en-tête Idempotent-Replay: true).
Maximum string length:
255Paramètres de chemin
L'identifiant (uuid) de la liste.
Corps
application/json
Maximum string length:
255Un groupe de règles ; un groupe peut en contenir un autre, sur deux niveaux au plus, 50 règles au plus.
Show child attributes
Show child attributes
Exemple:
{
"operator": "and",
"rules": [
{
"type": "tags",
"operator": "has_any",
"value": ["vip"]
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 60
}
]
}
Réponse
Le segment, avec son nombre d'abonnés.
Show child attributes
Show child attributes
⌘I
Créer un segment
curl --request POST \
--url https://{host}/api/v1/lists/{list}/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Anglophones actifs",
"conditions": {
"operator": "and",
"rules": [
{
"type": "language",
"operator": "equals",
"value": "en"
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 90
}
]
}
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Anglophones actifs',
conditions: {
operator: 'and',
rules: [
{type: 'language', operator: 'equals', value: 'en'},
{type: 'engagement', operator: 'active_within_days', value: 90}
]
}
})
};
fetch('https://{host}/api/v1/lists/{list}/segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{host}/api/v1/lists/{list}/segments",
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' => 'Anglophones actifs',
'conditions' => [
'operator' => 'and',
'rules' => [
[
'type' => 'language',
'operator' => 'equals',
'value' => 'en'
],
[
'type' => 'engagement',
'operator' => 'active_within_days',
'value' => 90
]
]
]
]),
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;
}import requests
url = "https://{host}/api/v1/lists/{list}/segments"
payload = {
"name": "Anglophones actifs",
"conditions": {
"operator": "and",
"rules": [
{
"type": "language",
"operator": "equals",
"value": "en"
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 90
}
]
}
}
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": "Clients VIP actifs",
"list": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"conditions": {
"operator": "and",
"rules": [
{
"type": "tags",
"operator": "has_any",
"value": [
"vip"
]
},
{
"type": "engagement",
"operator": "active_within_days",
"value": 60
}
]
},
"subscribers_count": 123,
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"message": "Unauthenticated."
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "Le champ email doit être une adresse e-mail valide.",
"errors": {}
}