import Migma from 'migma';
const migma = new Migma('YOUR_API_KEY');
const { data, error } = await migma.segments.update('SEGMENT_ID', {
name: 'Power Users',
projectId: 'PROJECT_ID'
});curl --request PATCH \
--url https://api.migma.ai/v1/segments/{id} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"projectId": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"customFields": {},
"fields": [
{
"key": "<string>",
"values": [
"<string>"
],
"mode": "is"
}
],
"activity": [
{
"channel": "email",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
}
}
'import requests
url = "https://api.migma.ai/v1/segments/{id}"
payload = {
"projectId": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": ["<string>"],
"excludeTags": ["<string>"],
"customFields": {},
"fields": [
{
"key": "<string>",
"values": ["<string>"],
"mode": "is"
}
],
"activity": [
{
"channel": "email",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
}
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.migma.ai/v1/segments/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'projectId' => '<string>',
'name' => '<string>',
'description' => '<string>',
'filters' => [
'match' => 'all',
'groups' => '<array>',
'tags' => [
'<string>'
],
'excludeTags' => [
'<string>'
],
'customFields' => [
],
'fields' => [
[
'key' => '<string>',
'values' => [
'<string>'
],
'mode' => 'is'
]
],
'activity' => [
[
'channel' => 'email',
'amount' => 4380,
'from' => '2023-11-07T05:31:56Z',
'to' => '2023-11-07T05:31:56Z',
'campaignId' => '<string>'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.migma.ai/v1/segments/{id}"
payload := strings.NewReader("{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.migma.ai/v1/segments/{id}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.migma.ai/v1/segments/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"status": "subscribed",
"validationStatus": "valid",
"customFields": {},
"fields": [
{
"key": "<string>",
"values": [
"<string>"
],
"mode": "is"
}
],
"activity": [
{
"action": "sent",
"mode": "within",
"channel": "email",
"unit": "hours",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
},
"count": 123,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"error": "<string>"
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}Update Segment
Update a segment. Requires API key with audience:write.
import Migma from 'migma';
const migma = new Migma('YOUR_API_KEY');
const { data, error } = await migma.segments.update('SEGMENT_ID', {
name: 'Power Users',
projectId: 'PROJECT_ID'
});curl --request PATCH \
--url https://api.migma.ai/v1/segments/{id} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"projectId": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"customFields": {},
"fields": [
{
"key": "<string>",
"values": [
"<string>"
],
"mode": "is"
}
],
"activity": [
{
"channel": "email",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
}
}
'import requests
url = "https://api.migma.ai/v1/segments/{id}"
payload = {
"projectId": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": ["<string>"],
"excludeTags": ["<string>"],
"customFields": {},
"fields": [
{
"key": "<string>",
"values": ["<string>"],
"mode": "is"
}
],
"activity": [
{
"channel": "email",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
}
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.migma.ai/v1/segments/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'projectId' => '<string>',
'name' => '<string>',
'description' => '<string>',
'filters' => [
'match' => 'all',
'groups' => '<array>',
'tags' => [
'<string>'
],
'excludeTags' => [
'<string>'
],
'customFields' => [
],
'fields' => [
[
'key' => '<string>',
'values' => [
'<string>'
],
'mode' => 'is'
]
],
'activity' => [
[
'channel' => 'email',
'amount' => 4380,
'from' => '2023-11-07T05:31:56Z',
'to' => '2023-11-07T05:31:56Z',
'campaignId' => '<string>'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.migma.ai/v1/segments/{id}"
payload := strings.NewReader("{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.migma.ai/v1/segments/{id}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.migma.ai/v1/segments/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"projectId\": \"<string>\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"filters\": {\n \"match\": \"all\",\n \"groups\": \"<array>\",\n \"tags\": [\n \"<string>\"\n ],\n \"excludeTags\": [\n \"<string>\"\n ],\n \"customFields\": {},\n \"fields\": [\n {\n \"key\": \"<string>\",\n \"values\": [\n \"<string>\"\n ],\n \"mode\": \"is\"\n }\n ],\n \"activity\": [\n {\n \"channel\": \"email\",\n \"amount\": 4380,\n \"from\": \"2023-11-07T05:31:56Z\",\n \"to\": \"2023-11-07T05:31:56Z\",\n \"campaignId\": \"<string>\"\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"id": "<string>",
"name": "<string>",
"description": "<string>",
"filters": {
"match": "all",
"groups": "<array>",
"tags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"status": "subscribed",
"validationStatus": "valid",
"customFields": {},
"fields": [
{
"key": "<string>",
"values": [
"<string>"
],
"mode": "is"
}
],
"activity": [
{
"action": "sent",
"mode": "within",
"channel": "email",
"unit": "hours",
"amount": 4380,
"from": "2023-11-07T05:31:56Z",
"to": "2023-11-07T05:31:56Z",
"campaignId": "<string>"
}
]
},
"count": 123,
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z"
},
"error": "<string>"
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}{
"success": false,
"error": "<string>",
"code": "<string>",
"data": {}
}Authorizations
API key authentication. Use 'Authorization: Bearer YOUR_API_KEY' where YOUR_API_KEY is obtained from the Migma dashboard under Settings → Developers → API Keys.
Path Parameters
Segment ID
Body
200500Each group combines its conditions and child groups using match: all (AND) by default, or any (OR). Values within one condition keep their existing semantics. At most 3 nested group levels below the root (root depth 0), 10 child groups per group, and 50 conditions across the entire tree. Each nonempty tags or excludeTags array, status, validationStatus, nonempty customFields key, fields entry, or activity entry counts as one condition; group containers do not count. Nested groups must contain a condition or a nonempty child group; the root may be empty. Campaign-specific activity requires all in its own group and every ancestor, but an any sibling is allowed. Send eligibility and project scope always apply outside these conditions.
Show child attributes
Show child attributes
Was this page helpful?