Node.js
import { Rewrite } from '@rewritetoday/sdk';
const rewrite = new Rewrite(process.env.REWRITE_API_KEY!);
const { data, error } = await rewrite.segments.create({
name: 'vip-customers',
description: 'Customers with priority transactional flows.',
color: '#0EA5E9',
});
if (error) throw error;{
"ok": true,
"data": {
"id": "748395130237498560",
"name": "vip-customers",
"description": "Customers with priority transactional flows.",
"contactsCount": 0,
"sandbox": false,
"updatedAt": "2026-03-20T14:22:31.562Z",
"createdAt": "2026-03-20T14:22:31.562Z"
}
}Segments
Create a segment
Create a reusable contact segment for grouping recipients.
POST
/
segments
Node.js
import { Rewrite } from '@rewritetoday/sdk';
const rewrite = new Rewrite(process.env.REWRITE_API_KEY!);
const { data, error } = await rewrite.segments.create({
name: 'vip-customers',
description: 'Customers with priority transactional flows.',
color: '#0EA5E9',
});
if (error) throw error;{
"ok": true,
"data": {
"id": "748395130237498560",
"name": "vip-customers",
"description": "Customers with priority transactional flows.",
"contactsCount": 0,
"sandbox": false,
"updatedAt": "2026-03-20T14:22:31.562Z",
"createdAt": "2026-03-20T14:22:31.562Z"
}
}Authorizations
Send your API key as Authorization: Bearer rw_....
Required scope: project:write.
Body
application/json
Unique segment name inside the current project.
Required string length:
1 - 80Example:
"vip-customers"
Optional description for operators and dashboards.
Required string length:
1 - 280Example:
"Customers with priority transactional flows."
Optional hexadecimal accent color stored with the segment.
Pattern:
^#[0-9A-Fa-f]{6}$Example:
"#0EA5E9"