Skip to main content
POST
/
v1
/
segments
Node.js SDK
import Migma from 'migma';

const migma = new Migma('YOUR_API_KEY');

const { data, error } = await migma.segments.create({
  name: 'Campaign openers',
  description: 'Users who opened a specific campaign in the last 14 days',
  filters: {
    activity: [{
      action: 'opened',
      channel: 'email',
      mode: 'within',
      unit: 'days',
      amount: 14,
      campaignId: 'CAMPAIGN_ID'
    }]
  },
  projectId: 'PROJECT_ID'
});
{
  "success": true,
  "data": {
    "id": "<string>",
    "name": "<string>",
    "description": "<string>",
    "filters": {
      "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>"
        }
      ]
    },
    "count": 123,
    "createdAt": "2023-11-07T05:31:56Z",
    "updatedAt": "2023-11-07T05:31:56Z"
  },
  "error": "<string>"
}

Authorizations

Authorization
string
header
required

API key authentication. Use 'Authorization: Bearer YOUR_API_KEY' where YOUR_API_KEY is obtained from the Migma dashboard under Settings → API Integration.

Body

application/json
name
string
required
Maximum string length: 200
projectId
string
required
description
string
Maximum string length: 500
filters
object

Response

Segment created

success
boolean
required
data
object
error
string | null