Skip to main content

Automation Reference

Complete reference guide for building automations in Alguna. This page documents all available triggers, actions, step types, template syntax, and condition expressions.

Trigger Types

Triggers define when an automation runs. Each trigger provides specific data that can be used in subsequent steps.

Payment Failed

Fires when a payment attempt fails.
PropertyTypeDescription
trigger_typePaymentFailedTrigger identifier
invoice_idstringThe invoice that failed to collect
payment_method_idstringPayment method used
failure_codestringReason for failure
failure_messagestringHuman-readable failure message
attempt_numberintegerWhich retry attempt (1, 2, 3…)
Example trigger data:
{
  "trigger_type": "PaymentFailed",
  "invoice_id": "inv_abc123",
  "account_id": "acc_xyz789",
  "payment_method_id": "pm_card_visa",
  "failure_code": "card_declined",
  "failure_message": "Your card was declined",
  "attempt_number": 1,
  "amount": "99.00",
  "currency": "USD"
}

Invoice Status Updated

Fires when an invoice status changes.
PropertyTypeDescription
trigger_typeInvoiceStatusUpdatedTrigger identifier
invoice_idstringThe invoice
previous_statusstringStatus before change
new_statusstringCurrent status
status_changed_attimestampWhen the change occurred
Status values: draft, issued, paid, void, past_due, uncollectible Example trigger data:
{
  "trigger_type": "InvoiceStatusUpdated",
  "invoice_id": "inv_abc123",
  "account_id": "acc_xyz789",
  "previous_status": "issued",
  "new_status": "paid",
  "status_changed_at": "2024-01-20T10:30:00Z"
}

Prepaid Usage Update

Fires when prepaid credit usage changes significantly.
PropertyTypeDescription
trigger_typePrepaidUsageUpdateTrigger identifier
wallet_idstringThe wallet affected
previous_balancedecimalBalance before update
current_balancedecimalCurrent balance
usage_amountdecimalAmount consumed
threshold_crossedbooleanIf a threshold was crossed
Example trigger data:
{
  "trigger_type": "PrepaidUsageUpdate",
  "wallet_id": "wal_abc123",
  "account_id": "acc_xyz789",
  "previous_balance": "1000.00",
  "current_balance": "150.00",
  "usage_amount": "850.00",
  "threshold_crossed": true,
  "threshold_percentage": 85
}

Subscription Sent for Signature

Fires when a subscription requires signature.
PropertyTypeDescription
trigger_typeSubscriptionSentForSignatureTrigger identifier
subscription_idstringThe subscription
version_idstringVersion requiring signature
sent_tostringEmail address
sent_attimestampWhen sent
Example trigger data:
{
  "trigger_type": "SubscriptionSentForSignature",
  "subscription_id": "sub_abc123",
  "version_id": "ver_xyz789",
  "account_id": "acc_def456",
  "sent_to": "[email protected]",
  "sent_at": "2024-01-20T10:30:00Z",
  "expires_at": "2024-01-27T10:30:00Z"
}

Credits Depleted

Fires when credit balance reaches zero or a threshold.
PropertyTypeDescription
trigger_typeCreditsDepletedTrigger identifier
wallet_idstringThe wallet
depleted_attimestampWhen depleted
last_grant_idstringMost recent credit grant
Example trigger data:
{
  "trigger_type": "CreditsDepleted",
  "wallet_id": "wal_abc123",
  "account_id": "acc_xyz789",
  "depleted_at": "2024-01-20T10:30:00Z",
  "final_balance": "0.00",
  "last_grant_id": "grant_def456"
}

Subscription Status Updated

Fires when a subscription status changes.
PropertyTypeDescription
trigger_typeSubscriptionStatusUpdatedTrigger identifier
subscription_idstringThe subscription
previous_statusstringStatus before change
new_statusstringCurrent status
Status values: draft, pending, active, paused, canceled, expired Example trigger data:
{
  "trigger_type": "SubscriptionStatusUpdated",
  "subscription_id": "sub_abc123",
  "account_id": "acc_xyz789",
  "previous_status": "active",
  "new_status": "canceled",
  "status_changed_at": "2024-01-20T10:30:00Z",
  "cancellation_reason": "customer_requested"
}

Action Types

Actions are the operations performed by your automation.

Communication Actions

send_email

Send an email using a template.
ParameterTypeRequiredDescription
template_idstringYesEmail template to use
tostringYesRecipient email (supports templates)
ccstring[]NoCC recipients
bccstring[]NoBCC recipients
variablesobjectNoTemplate variables
{
  "action": "send_email",
  "parameters": {
    "template_id": "tmpl_payment_failed",
    "to": "{{trigger.account.email}}",
    "variables": {
      "invoice_number": "{{trigger.invoice_id}}",
      "amount_due": "{{trigger.amount}}"
    }
  }
}

send_invoice_reminder

Send a payment reminder for an invoice.
ParameterTypeRequiredDescription
invoice_idstringYesInvoice to remind about
reminder_typestringNogentle, firm, final
{
  "action": "send_invoice_reminder",
  "parameters": {
    "invoice_id": "{{trigger.invoice_id}}",
    "reminder_type": "gentle"
  }
}

send_invoice_reminders_bulk

Send reminders for multiple invoices.
ParameterTypeRequiredDescription
invoice_idsstring[]YesInvoices to remind about
reminder_typestringNoReminder severity level
{
  "action": "send_invoice_reminders_bulk",
  "parameters": {
    "invoice_ids": "{{step_get_invoices.outputs.invoice_ids}}",
    "reminder_type": "firm"
  }
}

send_billing_info_request

Request updated billing information from customer.
ParameterTypeRequiredDescription
account_idstringYesCustomer account
reasonstringNoWhy info is needed
{
  "action": "send_billing_info_request",
  "parameters": {
    "account_id": "{{trigger.account_id}}",
    "reason": "Payment method expired"
  }
}
Send customer portal access link.
ParameterTypeRequiredDescription
account_idstringYesCustomer account
expires_instringNoLink expiration (e.g., 7d)
{
  "action": "share_customer_portal_link",
  "parameters": {
    "account_id": "{{trigger.account_id}}",
    "expires_in": "7d"
  }
}

send_subscription_signature_reminder

Remind customer to sign a pending subscription.
ParameterTypeRequiredDescription
subscription_idstringYesSubscription awaiting signature
version_idstringNoSpecific version
{
  "action": "send_subscription_signature_reminder",
  "parameters": {
    "subscription_id": "{{trigger.subscription_id}}",
    "version_id": "{{trigger.version_id}}"
  }
}

send_subscriptions_autorenewal_notification_bulk

Notify customers about upcoming auto-renewals.
ParameterTypeRequiredDescription
subscription_idsstring[]YesSubscriptions renewing
days_beforeintegerNoDays before renewal
{
  "action": "send_subscriptions_autorenewal_notification_bulk",
  "parameters": {
    "subscription_ids": "{{step_get_subs.outputs.ids}}",
    "days_before": 30
  }
}

Data Retrieval Actions

get_invoice

Retrieve a single invoice.
ParameterTypeRequiredDescription
invoice_idstringYesInvoice to retrieve
Outputs: Full invoice object including line items, status, amounts.
{
  "action": "get_invoice",
  "parameters": {
    "invoice_id": "{{trigger.invoice_id}}"
  }
}

get_invoices

Retrieve multiple invoices with filters.
ParameterTypeRequiredDescription
account_idstringNoFilter by account
statusstring[]NoFilter by status
due_beforestringNoFilter by due date
limitintegerNoMax results
Outputs: Array of invoice objects.
{
  "action": "get_invoices",
  "parameters": {
    "account_id": "{{trigger.account_id}}",
    "status": ["issued", "past_due"],
    "limit": 10
  }
}

get_subscription

Retrieve a single subscription.
ParameterTypeRequiredDescription
subscription_idstringYesSubscription to retrieve
Outputs: Full subscription object with current version.
{
  "action": "get_subscription",
  "parameters": {
    "subscription_id": "{{trigger.subscription_id}}"
  }
}

get_subscriptions

Retrieve multiple subscriptions with filters.
ParameterTypeRequiredDescription
account_idstringNoFilter by account
statusstring[]NoFilter by status
renews_beforestringNoFilter by renewal date
Outputs: Array of subscription objects.
{
  "action": "get_subscriptions",
  "parameters": {
    "status": ["active"],
    "renews_before": "{{now | date_add: '30d'}}"
  }
}

Billing Actions

retry_invoice_payment

Retry payment collection for an invoice.
ParameterTypeRequiredDescription
invoice_idstringYesInvoice to retry
payment_method_idstringNoSpecific payment method
{
  "action": "retry_invoice_payment",
  "parameters": {
    "invoice_id": "{{trigger.invoice_id}}"
  }
}

cancel_subscription

Cancel a subscription.
ParameterTypeRequiredDescription
subscription_idstringYesSubscription to cancel
cancel_atstringNoimmediate or end_of_period
reasonstringNoCancellation reason
{
  "action": "cancel_subscription",
  "parameters": {
    "subscription_id": "{{trigger.subscription_id}}",
    "cancel_at": "end_of_period",
    "reason": "Non-payment after multiple attempts"
  }
}

Integration Actions

send_webhook

Send data to an external webhook.
ParameterTypeRequiredDescription
urlstringYesWebhook endpoint
methodstringNoHTTP method (default: POST)
headersobjectNoCustom headers
bodyobjectYesRequest payload
{
  "action": "send_webhook",
  "parameters": {
    "url": "https://api.yourapp.com/billing-events",
    "method": "POST",
    "headers": {
      "Authorization": "Bearer {{secrets.WEBHOOK_TOKEN}}"
    },
    "body": {
      "event": "payment_failed",
      "account_id": "{{trigger.account_id}}",
      "invoice_id": "{{trigger.invoice_id}}"
    }
  }
}

Step Types

Automations are composed of steps that execute in sequence.

Action Step

Execute a single action.
{
  "id": "send_reminder",
  "type": "Action",
  "action": "send_email",
  "parameters": {...}
}

Condition Step

Branch based on a condition.
{
  "id": "check_attempts",
  "type": "Condition",
  "condition": "trigger.attempt_number > 2",
  "then": [...],
  "else": [...]
}

Delay Step

Wait before continuing.
{
  "id": "wait_24h",
  "type": "Delay",
  "duration": "24h"
}
Duration formats: 30m (minutes), 24h (hours), 7d (days)

ForEach Step

Iterate over a collection.
{
  "id": "process_invoices",
  "type": "ForEach",
  "collection": "{{step_get_invoices.outputs.invoices}}",
  "item_variable": "invoice",
  "steps": [
    {
      "id": "send_reminder",
      "type": "Action",
      "action": "send_invoice_reminder",
      "parameters": {
        "invoice_id": "{{invoice.id}}"
      }
    }
  ]
}

DoUntil Step

Repeat until a condition is met.
{
  "id": "retry_payment",
  "type": "DoUntil",
  "condition": "step_check_status.outputs.status == 'paid' || iteration > 3",
  "steps": [
    {
      "id": "attempt_payment",
      "type": "Action",
      "action": "retry_invoice_payment",
      "parameters": {...}
    },
    {
      "id": "wait",
      "type": "Delay",
      "duration": "24h"
    }
  ]
}

Template Syntax

Use templates to reference dynamic data in your automation.

Basic Syntax

Access data using double curly braces:
{{trigger.account_id}}
{{step_id.outputs.field}}
{{variable_name}}

Accessing Trigger Data

{{trigger.invoice_id}}        // Direct field
{{trigger.account.name}}      // Nested field
{{trigger.account.email}}     // Customer email

Accessing Step Outputs

Reference outputs from previous steps:
{{step_get_invoice.outputs.total}}
{{step_get_subscription.outputs.plan_id}}
{{step_get_invoices.outputs.invoices[0].id}}

Built-in Variables

VariableDescription
{{now}}Current timestamp
{{today}}Current date
{{iteration}}Current loop iteration (in ForEach/DoUntil)
{{secrets.KEY}}Access stored secrets

Filters

Transform values with filters:
{{trigger.amount | currency}}           // Format as currency
{{trigger.due_date | date: 'MMM D'}}   // Format date
{{trigger.name | uppercase}}            // Convert to uppercase
{{trigger.name | lowercase}}            // Convert to lowercase
{{trigger.items | length}}              // Array length
{{now | date_add: '7d'}}                // Add to date
{{now | date_subtract: '30d'}}          // Subtract from date

Condition Syntax

Conditions use the Expr expression language.

Comparison Operators

OperatorDescriptionExample
==Equaltrigger.status == 'paid'
!=Not equaltrigger.status != 'draft'
>Greater thantrigger.amount > 100
>=Greater or equaltrigger.attempt_number >= 3
<Less thantrigger.balance < 50
<=Less or equaltrigger.days_overdue <= 30

Logical Operators

OperatorDescriptionExample
&&ANDtrigger.status == 'past_due' && trigger.amount > 100
||ORtrigger.status == 'paid' || trigger.status == 'void'
!NOT!trigger.is_test

String Operations

trigger.email contains '@gmail.com'
trigger.name startsWith 'Acme'
trigger.description endsWith 'trial'
trigger.plan_id in ['plan_basic', 'plan_pro']

Array Operations

len(trigger.line_items) > 0
trigger.tags contains 'enterprise'
any(trigger.invoices, {.status == 'past_due'})
all(trigger.payments, {.status == 'succeeded'})

Null Checks

trigger.discount != nil
trigger.coupon_code ?? 'NONE'

Complete Examples

Dunning Automation

Progressive payment failure handling:
{
  "name": "Payment Dunning Workflow",
  "trigger": {
    "type": "PaymentFailed"
  },
  "steps": [
    {
      "id": "check_attempt",
      "type": "Condition",
      "condition": "trigger.attempt_number == 1",
      "then": [
        {
          "id": "gentle_reminder",
          "type": "Action",
          "action": "send_email",
          "parameters": {
            "template_id": "tmpl_payment_failed_gentle",
            "to": "{{trigger.account.email}}"
          }
        },
        {
          "id": "wait_3_days",
          "type": "Delay",
          "duration": "3d"
        },
        {
          "id": "retry_1",
          "type": "Action",
          "action": "retry_invoice_payment",
          "parameters": {
            "invoice_id": "{{trigger.invoice_id}}"
          }
        }
      ],
      "else": [
        {
          "id": "check_final",
          "type": "Condition",
          "condition": "trigger.attempt_number >= 3",
          "then": [
            {
              "id": "final_notice",
              "type": "Action",
              "action": "send_email",
              "parameters": {
                "template_id": "tmpl_payment_failed_final",
                "to": "{{trigger.account.email}}"
              }
            },
            {
              "id": "cancel_sub",
              "type": "Action",
              "action": "cancel_subscription",
              "parameters": {
                "subscription_id": "{{trigger.subscription_id}}",
                "cancel_at": "immediate",
                "reason": "Payment failed after 3 attempts"
              }
            }
          ]
        }
      ]
    }
  ]
}

Renewal Notification Automation

Notify customers before renewal:
{
  "name": "Renewal Notifications",
  "trigger": {
    "type": "SubscriptionStatusUpdated",
    "filters": {
      "new_status": "active"
    }
  },
  "schedule": {
    "cron": "0 9 * * *"
  },
  "steps": [
    {
      "id": "get_renewing_subs",
      "type": "Action",
      "action": "get_subscriptions",
      "parameters": {
        "status": ["active"],
        "renews_before": "{{now | date_add: '30d'}}"
      }
    },
    {
      "id": "filter_annual",
      "type": "Condition",
      "condition": "len(step_get_renewing_subs.outputs.subscriptions) > 0",
      "then": [
        {
          "id": "notify_customers",
          "type": "Action",
          "action": "send_subscriptions_autorenewal_notification_bulk",
          "parameters": {
            "subscription_ids": "{{step_get_renewing_subs.outputs.subscriptions | map: 'id'}}"
          }
        }
      ]
    }
  ]
}

Low Credit Balance Alert

Alert when credits are running low:
{
  "name": "Low Credit Alert",
  "trigger": {
    "type": "PrepaidUsageUpdate"
  },
  "steps": [
    {
      "id": "check_threshold",
      "type": "Condition",
      "condition": "trigger.threshold_crossed && trigger.threshold_percentage >= 80",
      "then": [
        {
          "id": "alert_customer",
          "type": "Action",
          "action": "send_email",
          "parameters": {
            "template_id": "tmpl_low_credits",
            "to": "{{trigger.account.email}}",
            "variables": {
              "remaining_balance": "{{trigger.current_balance}}",
              "usage_percentage": "{{trigger.threshold_percentage}}"
            }
          }
        },
        {
          "id": "notify_webhook",
          "type": "Action",
          "action": "send_webhook",
          "parameters": {
            "url": "{{secrets.SLACK_WEBHOOK}}",
            "body": {
              "text": "Low credit alert: {{trigger.account.name}} at {{trigger.threshold_percentage}}% usage"
            }
          }
        }
      ]
    }
  ]
}

Error Handling

Retry Configuration

Configure retry behavior for actions:
{
  "action": "send_webhook",
  "parameters": {...},
  "retry": {
    "max_attempts": 3,
    "backoff": "exponential",
    "initial_delay": "30s"
  }
}

On Error Handling

Define behavior when a step fails:
{
  "id": "risky_action",
  "type": "Action",
  "action": "retry_invoice_payment",
  "parameters": {...},
  "on_error": {
    "action": "continue",
    "notify": "{{secrets.ALERT_EMAIL}}"
  }
}
Error actions:
  • stop - Halt automation
  • continue - Skip and continue
  • goto - Jump to specific step

Best Practices

Use Descriptive IDs

Name steps clearly: send_gentle_reminder not step_1.

Test with Small Batches

Test automations with filtered triggers before going live.

Add Delays Thoughtfully

Avoid overwhelming customers with rapid-fire communications.

Log External Calls

Use webhooks to log automation events for debugging.

Next Steps