curl -X POST "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/environments/env123/buckets/bkt_xyz789uvw012rst345abc/workflows" \
  -H "Authorization: Bearer your-jwt-token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Error Alert Workflow",
    "description": "Send Slack notification when error rate exceeds 5%",
    "trigger": {
      "type": "threshold",
      "conditions": [
        {
          "metric": "error_rate",
          "operator": "greater_than",
          "value": 5,
          "timeWindow": "5m"
        }
      ]
    },
    "actions": [
      {
        "type": "slack",
        "config": {
          "webhook_url": "https://hooks.slack.com/services/...",
          "channel": "#alerts",
          "message": "🚨 Error rate exceeded 5% in {{bucket.name}}"
        },
        "order": 1
      }
    ],
    "isActive": true
  }'
{
  "sid": "wfl_abc123def456ghi789jkl012",
  "accountSid": "acc_abc123def456ghi789jkl012",
  "environmentSid": "env123",
  "bucketSid": "bkt_xyz789uvw012rst345abc",
  "name": "Error Alert Workflow",
  "description": "Send Slack notification when error rate exceeds 5%",
  "trigger": {
    "type": "threshold",
    "conditions": [
      {
        "metric": "error_rate",
        "operator": "greater_than",
        "value": 5,
        "timeWindow": "5m"
      }
    ]
  },
  "actions": [
    {
      "type": "slack",
      "config": {
        "webhook_url": "https://hooks.slack.com/services/...",
        "channel": "#alerts",
        "message": "🚨 Error rate exceeded 5% in {{bucket.name}}"
      },
      "order": 1
    }
  ],
  "isActive": true,
  "createdAt": "2023-12-01T15:45:00.000Z"
}

Create Workflow

Create a new automated workflow that triggers based on API traffic patterns and conditions.

Path Parameters

accountSid
string
required
Account identifier (format: acc_ followed by 27 alphanumeric characters)
environmentSid
string
required
Environment identifier (6 character alphanumeric)
bucketSid
string
required
Bucket identifier

Headers

Authorization
string
required
Bearer token for authentication

Request Body

name
string
required
Name of the workflow
description
string
Description of what this workflow does
trigger
object
required
actions
array
required
isActive
boolean
Whether this workflow should be active (default: true)

Response

sid
string
Unique workflow identifier
accountSid
string
Account identifier this workflow belongs to
environmentSid
string
Environment identifier
bucketSid
string
Bucket identifier this workflow is associated with
name
string
Name of the workflow
description
string
Description of the workflow
trigger
object
Trigger configuration
actions
array
Array of workflow actions
isActive
boolean
Whether the workflow is currently active
createdAt
string
ISO 8601 timestamp of workflow creation
curl -X POST "https://api.apitraffic.io/v1/accounts/acc_abc123def456ghi789jkl012/environments/env123/buckets/bkt_xyz789uvw012rst345abc/workflows" \
  -H "Authorization: Bearer your-jwt-token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Error Alert Workflow",
    "description": "Send Slack notification when error rate exceeds 5%",
    "trigger": {
      "type": "threshold",
      "conditions": [
        {
          "metric": "error_rate",
          "operator": "greater_than",
          "value": 5,
          "timeWindow": "5m"
        }
      ]
    },
    "actions": [
      {
        "type": "slack",
        "config": {
          "webhook_url": "https://hooks.slack.com/services/...",
          "channel": "#alerts",
          "message": "🚨 Error rate exceeded 5% in {{bucket.name}}"
        },
        "order": 1
      }
    ],
    "isActive": true
  }'
{
  "sid": "wfl_abc123def456ghi789jkl012",
  "accountSid": "acc_abc123def456ghi789jkl012",
  "environmentSid": "env123",
  "bucketSid": "bkt_xyz789uvw012rst345abc",
  "name": "Error Alert Workflow",
  "description": "Send Slack notification when error rate exceeds 5%",
  "trigger": {
    "type": "threshold",
    "conditions": [
      {
        "metric": "error_rate",
        "operator": "greater_than",
        "value": 5,
        "timeWindow": "5m"
      }
    ]
  },
  "actions": [
    {
      "type": "slack",
      "config": {
        "webhook_url": "https://hooks.slack.com/services/...",
        "channel": "#alerts",
        "message": "🚨 Error rate exceeded 5% in {{bucket.name}}"
      },
      "order": 1
    }
  ],
  "isActive": true,
  "createdAt": "2023-12-01T15:45:00.000Z"
}

Workflow Trigger Types

Request Trigger

Triggers when specific requests are made to your API.
{
  "type": "request",
  "conditions": [
    {
      "path": "/api/users",
      "method": "POST",
      "statusCode": 201
    }
  ]
}

Error Trigger

Triggers when errors occur in your API.
{
  "type": "error",
  "conditions": [
    {
      "statusCode": 500,
      "path": "/api/*"
    }
  ]
}

Threshold Trigger

Triggers when metrics cross specified thresholds.
{
  "type": "threshold",
  "conditions": [
    {
      "metric": "response_time",
      "operator": "greater_than",
      "value": 1000,
      "timeWindow": "5m"
    }
  ]
}

Schedule Trigger

Triggers on a scheduled basis using cron expressions.
{
  "type": "schedule",
  "schedule": "0 9 * * MON-FRI"
}

Workflow Action Types

Webhook Action

Send HTTP requests to external services.
{
  "type": "webhook",
  "config": {
    "url": "https://api.example.com/webhook",
    "method": "POST",
    "headers": {
      "Authorization": "Bearer token"
    },
    "body": {
      "message": "Alert from ApiTraffic",
      "data": "{{request.body}}"
    }
  }
}

Email Action

Send email notifications.
{
  "type": "email",
  "config": {
    "to": ["admin@example.com"],
    "subject": "API Alert: {{trigger.type}}",
    "body": "An alert was triggered in bucket {{bucket.name}}"
  }
}

Slack Action

Send messages to Slack channels.
{
  "type": "slack",
  "config": {
    "webhook_url": "https://hooks.slack.com/services/...",
    "channel": "#alerts",
    "message": "🚨 {{trigger.message}}",
    "username": "ApiTraffic Bot"
  }
}

ActivePieces Action

Trigger ActivePieces workflows for complex automation.
{
  "type": "activepieces",
  "config": {
    "flow_id": "flow_abc123",
    "webhook_url": "https://flow.apitraffic.io/webhook/...",
    "data": {
      "request": "{{request}}",
      "response": "{{response}}"
    }
  }
}

Template Variables

Workflows support template variables that are dynamically replaced with actual values:

Request Variables

  • {{request.method}} - HTTP method
  • {{request.path}} - Request path
  • {{request.headers}} - Request headers
  • {{request.body}} - Request body
  • {{request.query}} - Query parameters

Response Variables

  • {{response.statusCode}} - HTTP status code
  • {{response.headers}} - Response headers
  • {{response.body}} - Response body
  • {{response.size}} - Response size in bytes

Timing Variables

  • {{timings.duration}} - Total request duration
  • {{timings.responseTime}} - Response time

Context Variables

  • {{bucket.name}} - Bucket name
  • {{bucket.sid}} - Bucket ID
  • {{account.name}} - Account name
  • {{environment.name}} - Environment name

Metric Variables (for threshold triggers)

  • {{metric.value}} - Current metric value
  • {{metric.threshold}} - Configured threshold
  • {{metric.timeWindow}} - Time window for the metric

Common Workflow Examples

High Error Rate Alert

{
  "name": "High Error Rate Alert",
  "trigger": {
    "type": "threshold",
    "conditions": [
      {
        "metric": "error_rate",
        "operator": "greater_than",
        "value": 10,
        "timeWindow": "5m"
      }
    ]
  },
  "actions": [
    {
      "type": "slack",
      "config": {
        "message": "🚨 Error rate is {{metric.value}}% in {{bucket.name}}"
      }
    }
  ]
}

Slow Response Alert

{
  "name": "Slow Response Alert",
  "trigger": {
    "type": "threshold",
    "conditions": [
      {
        "metric": "avg_response_time",
        "operator": "greater_than",
        "value": 2000,
        "timeWindow": "10m"
      }
    ]
  },
  "actions": [
    {
      "type": "email",
      "config": {
        "subject": "Slow API Performance Alert",
        "body": "Average response time is {{metric.value}}ms"
      }
    }
  ]
}

New User Registration

{
  "name": "New User Registration",
  "trigger": {
    "type": "request",
    "conditions": [
      {
        "path": "/api/users",
        "method": "POST",
        "statusCode": 201
      }
    ]
  },
  "actions": [
    {
      "type": "webhook",
      "config": {
        "url": "https://crm.example.com/webhook",
        "body": {
          "event": "user_registered",
          "user_data": "{{request.body}}"
        }
      }
    }
  ]
}

Daily Summary Report

{
  "name": "Daily Summary Report",
  "trigger": {
    "type": "schedule",
    "schedule": "0 9 * * *"
  },
  "actions": [
    {
      "type": "email",
      "config": {
        "subject": "Daily API Summary for {{bucket.name}}",
        "body": "Your daily API traffic summary is ready."
      }
    }
  ]
}