Traits API

Traits are reusable computed properties attached to a parent entity model. They let you define aggregations, occurrences, lists, formulas, and custom SQL calculations that enrich your customer profiles and power audience segmentation.

Endpoints

MethodPathDescription
GET/api/v1/workspaces/{id}/traitsList all traits
POST/api/v1/workspaces/{id}/traitsCreate a trait
GET/api/v1/workspaces/{id}/traits/{traitId}Get a trait
PUT/api/v1/workspaces/{id}/traits/{traitId}Update a trait
DELETE/api/v1/workspaces/{id}/traits/{traitId}Delete a trait
GET/api/v1/workspaces/{id}/models/{modelId}/traitsList traits by model
POST/api/v1/workspaces/{id}/traits/{traitId}/triggerTrigger trait evaluation
GET/api/v1/workspaces/{id}/traits/{traitId}/runsList trait runs

List Traits

GET /api/v1/workspaces/{id}/traits

Returns all traits in the workspace.

Response

[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "workspace_id": "660e8400-e29b-41d4-a716-446655440000",
    "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
    "name": "Total Purchases",
    "slug": "total_purchases",
    "description": "Total number of purchases per customer",
    "trait_type": "aggregation",
    "config": {
      "source_model_id": "880e8400-e29b-41d4-a716-446655440000",
      "relationship_id": "990e8400-e29b-41d4-a716-446655440000",
      "aggregation": "count",
      "column": "order_id"
    },
    "result_type": "number",
    "status": "active",
    "status_error": "",
    "created_by": "aae8400-e29b-41d4-a716-446655440000",
    "created_at": "2024-01-15T09:30:00Z",
    "updated_at": "2024-01-15T09:30:00Z",
    "last_computed_at": "2024-01-15T15:00:00Z"
  }
]

Example

curl -X GET https://your-instance.signalsmith.io/api/v1/workspaces/{id}/traits \
  -H "Authorization: Bearer <token>" \
  -H "X-Workspace-ID: <workspace-id>"

Create Trait

POST /api/v1/workspaces/{id}/traits

Creates a new trait definition.

Request Body

FieldTypeRequiredDescription
namestringYesDisplay name
descriptionstringNoDescription
parent_model_idstring (UUID)YesParent entity model this trait attaches to
trait_typestringYesaggregation, occurrence, list, sql, or formula
configobjectYesTrait-specific configuration (varies by type)
result_typestringYestext, number, boolean, timestamp, or array

Trait Types

Aggregation

Computes an aggregate value (count, sum, avg, min, max) across a related model.

{
  "name": "Total Revenue",
  "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
  "trait_type": "aggregation",
  "config": {
    "source_model_id": "880e8400-e29b-41d4-a716-446655440000",
    "relationship_id": "990e8400-e29b-41d4-a716-446655440000",
    "aggregation": "sum",
    "column": "order_total"
  },
  "result_type": "number"
}

Occurrence

Detects whether or when an event occurred (first, last, exists).

{
  "name": "Last Purchase Date",
  "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
  "trait_type": "occurrence",
  "config": {
    "source_model_id": "880e8400-e29b-41d4-a716-446655440000",
    "relationship_id": "990e8400-e29b-41d4-a716-446655440000",
    "occurrence": "last",
    "column": "order_date"
  },
  "result_type": "timestamp"
}

List

Collects distinct values into an array.

{
  "name": "Product Categories",
  "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
  "trait_type": "list",
  "config": {
    "source_model_id": "880e8400-e29b-41d4-a716-446655440000",
    "relationship_id": "990e8400-e29b-41d4-a716-446655440000",
    "column": "category"
  },
  "result_type": "array"
}

SQL

Custom SQL expression evaluated per entity.

{
  "name": "Customer Tier",
  "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
  "trait_type": "sql",
  "config": {
    "sql_expression": "CASE WHEN lifetime_value > 10000 THEN 'platinum' WHEN lifetime_value > 1000 THEN 'gold' ELSE 'standard' END"
  },
  "result_type": "text"
}

Formula

Combines other traits using arithmetic or logic.

{
  "name": "Average Order Value",
  "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
  "trait_type": "formula",
  "config": {
    "expression": "{total_revenue} / NULLIF({total_purchases}, 0)"
  },
  "result_type": "number"
}

Example

curl -X POST https://your-instance.signalsmith.io/api/v1/workspaces/{id}/traits \
  -H "Authorization: Bearer <token>" \
  -H "X-Workspace-ID: <workspace-id>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Total Purchases",
    "parent_model_id": "770e8400-e29b-41d4-a716-446655440000",
    "trait_type": "aggregation",
    "config": {
      "source_model_id": "880e8400-e29b-41d4-a716-446655440000",
      "relationship_id": "990e8400-e29b-41d4-a716-446655440000",
      "aggregation": "count",
      "column": "order_id"
    },
    "result_type": "number"
  }'

Get Trait

GET /api/v1/workspaces/{id}/traits/{traitId}

Returns a single trait by ID.

Example

curl -X GET https://your-instance.signalsmith.io/api/v1/workspaces/{id}/traits/{traitId} \
  -H "Authorization: Bearer <token>" \
  -H "X-Workspace-ID: <workspace-id>"

Update Trait

PUT /api/v1/workspaces/{id}/traits/{traitId}

Updates an existing trait definition.

Request Body

Same fields as create. Only include fields you want to change.

Example

curl -X PUT https://your-instance.signalsmith.io/api/v1/workspaces/{id}/traits/{traitId} \
  -H "Authorization: Bearer <token>" \
  -H "X-Workspace-ID: <workspace-id>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Total Purchases (All Time)",
    "description": "Count of all orders per customer"
  }'

Delete Trait

DELETE /api/v1/workspaces/{id}/traits/{traitId}

Deletes a trait. Cannot be deleted if audiences reference it in their filter trees.

Response

{
  "status": "deleted"
}

List Traits by Model

GET /api/v1/workspaces/{id}/models/{modelId}/traits

Returns all traits attached to a specific parent model.

Example

curl -X GET https://your-instance.signalsmith.io/api/v1/workspaces/{id}/models/{modelId}/traits \
  -H "Authorization: Bearer <token>" \
  -H "X-Workspace-ID: <workspace-id>"

Trigger Trait Evaluation

POST /api/v1/workspaces/{id}/traits/{traitId}/trigger

Manually triggers a trait evaluation run. The trait’s computed values are recalculated against the latest source data.

Response

Returns the created trait run object with status 201 Created.


List Trait Runs

GET /api/v1/workspaces/{id}/traits/{traitId}/runs

Returns the evaluation history for a trait.


Trait Object

FieldTypeDescription
idstring (UUID)Unique identifier
workspace_idstring (UUID)Owning workspace
parent_model_idstring (UUID)Parent entity model
namestringDisplay name
slugstringURL-safe identifier
descriptionstringDescription
trait_typestringaggregation, occurrence, list, sql, or formula
configobjectType-specific configuration
result_typestringtext, number, boolean, timestamp, or array
statusstringdraft, active, or error
status_errorstringError message when status is error
created_bystring (UUID)Account that created the trait
created_atstring (ISO 8601)Creation timestamp
updated_atstring (ISO 8601)Last update timestamp
last_computed_atstring (ISO 8601) or nullLast successful evaluation time