Skip to main content

Functions Step

The Functions step provides access to QuivaWorks platform services (streams, storage) and data transformation utilities (encoding, merging, templating). Use Functions to interact with real-time streams, persist data, and transform formats.
Platform Integration: Functions connect your flows to QuivaWorks’ infrastructure for real-time streaming, persistent storage, and data transformation.

How Functions Work

Functions take input, execute an operation (platform service or transformation), and return the result:
Agent: Generates event data

Functions: Publish to stream
  Function: publish-message-to-stream
  Stream: "user-events"
  Message: ${agent.output}

Event published to real-time stream

When to Use Functions

Use Functions WhenUse Alternative When
Need real-time streamingBatch processing (use HTTP/database)
Persist configuration/stateTemporary data in flow
Store files/mediaExternal storage service preferred
Transform data formats (JSON/XML/Base64)Complex custom logic (use Eval)
Merge complex data structuresSimple field extraction (use Map)
Examples: Use Functions: Publish events to stream for real-time analytics
Use HTTP instead: Send to external webhook (when external service required)
Use Functions: Store user preferences in KV storage
Pass in flow: Temporary data that doesn’t need persistence
Use Functions: Decode Base64 encoded data
Use Eval instead: Complex custom encoding algorithm (when custom logic needed)

Function Categories

QuivaWorks provides functions across multiple categories:

Configuration

Function Selection

function
string
required
Which function to executeExamples:
publish-message-to-stream
put-kv-item
base64-encode
deep-merge-objects

Function Inputs

inputs
object
required
Input parameters for the functionCan reference previous steps:
{
  "text": "${trigger.body.message}",
  "maxLength": 100
}
Each function has specific input requirements (see function documentation)

Quick Examples by Category

Stream Functions

{
  "function": "publish-message-to-stream",
  "inputs": {
    "stream": "user-events",
    "message": {
      "event": "purchase",
      "user_id": "${customer.id}",
      "amount": "${order.total}",
      "timestamp": "${now}"
    }
  }
}

Key-Value Storage

{
  "function": "put-kv-item",
  "inputs": {
    "bucket": "app-config",
    "key": "feature-flags",
    "value": {
      "new_ui": true,
      "beta_features": false
    }
  }
}

Object Storage

{
  "function": "put-object-by-key",
  "inputs": {
    "bucket": "user-uploads",
    "key": "documents/${user.id}/${filename}",
    "object": "${file_data}"
  }
}

Data Transformation Utilities

{
  "function": "base64-encode",
  "inputs": "${data}"
}

Complete Function Documentation

For detailed documentation of all available functions with syntax, parameters, and examples:

Common Flow Patterns

Track user events in real-time stream
Trigger: User action

Agent: Enrich event data

Functions: Publish to stream
  Function: publish-message-to-stream
  Stream: "user-events"
  Message: ${agent.output}

Functions: Store in KV for quick access
  Function: put-kv-item
  Bucket: "recent-events"
  Key: ${user.id}
  Value: ${agent.output}
Use when: Need real-time event processing and analytics
Store and retrieve app configuration
Trigger: Config update request

Functions: Save configuration
  Function: put-kv-item
  Bucket: "app-config"
  Key: ${config.key}
  Value: ${config.value}

(Later) Flow needs config

Functions: Retrieve configuration
  Function: get-kv-bucket-item
  Bucket: "app-config"
  Key: "feature-flags"

Agent: Use configuration
Use when: Need persistent configuration across flows
Handle file uploads with object storage
Form: File upload

Functions: Encode file
  Function: base64-encode
  Input: ${form.file}

Functions: Store file
  Function: put-object-by-key
  Bucket: "uploads"
  Key: "files/${user.id}/${filename}"
  Object: ${encoded_file}

Agent: Send confirmation with file URL
Use when: Need to store files/media
Convert between data formats
HTTP Request: Receives JSON data

Functions: Convert to XML
  Function: json-xml
  JSON: ${http.body}
  Options: {compact: true}

Functions: Encode for transmission
  Function: base64-encode
  Input: ${xml_data}

HTTP Request: Send to legacy system
Use when: Integrating systems with different formats
Merge data from multiple sources
HTTP Request 1: Get user profile

HTTP Request 2: Get preferences  

Functions: Get cached data
  Function: get-kv-bucket-item
  Bucket: "user-cache"
  Key: ${user.id}

Functions: Deep merge all data
  Function: deep-merge-objects
  Objects: [${profile}, ${preferences}, ${cached}]

Agent: Use complete user data
Use when: Need to combine nested data structures
Generate dynamic content from templates
Agent: Prepare email data

Functions: Render template
  Function: handlebars
  Template: "Hello {{name}}, your order {{order_id}}..."
  Variables: ${agent.output}

HTTP Request: Send email via SendGrid
Use when: Need dynamic content generation
Organize data for analysis
Database: Get all orders

Functions: Group by customer
  Function: group-by
  Array: ${orders}
  Property: "customer_id"

Map: Calculate per-customer totals

Functions: Store aggregated data
  Function: put-kv-item
  Bucket: "analytics"
  Key: "customer-totals"
Use when: Need to organize data by property
Aggregate and analyze stream data
Trigger: Schedule (hourly)

Functions: Aggregate stream items
  Function: aggregate-stream-items
  Stream: "user-events"
  Key: "event_type"
  TimeWindow: "1h"

Agent: Generate insights report

Functions: Store insights
  Function: put-kv-item
  Bucket: "analytics"
  Key: "hourly-summary-${timestamp}"
Use when: Need to analyze streaming data
Upload files to partner SFTP servers
Agent: Generate report

Functions: Get SFTP credentials
  Function: secret-key-get-node
  Key: "partner_sftp_password"

Functions: Upload via SFTP
  Function: sftp
  Host: "partner.sftp.com"
  FileContents: ${report_data}
  FilePath: "/incoming/daily-report.pdf"
  Password: ${secret.value}

HTTP Request: Notify partner of upload
Use when: Need to deliver files to partners/systems via SFTP
Chain multiple functions together
Trigger: Receive webhook

Functions: Invoke validation function
  Function: function-invoke
  Type: RequestResponse
  Subject: "webhook-validator"
  Payload: ${webhook.data}

Functions: Invoke processor if valid
  Function: function-invoke
  Type: Async
  Subject: "data-processor"
  Payload: ${validated_data}

Response: Return success
Use when: Need modular function composition
Work with XML-based SOAP APIs
Agent: Build request data (JSON)

Functions: Convert to XML
  Function: json-xml
  JSON: ${agent.output}
  Options: {compact: true}

HTTP Request: Call SOAP API
  Body: ${xml_request}

Functions: Parse XML response
  Function: xml-json
  XML: ${http.response}
  Options: {compact: true, trim: true}

Agent: Process JSON data
Use when: Integrating with SOAP/XML services

Best Practices

Use Platform Functions

Use QuivaWorks’ platform functions for streams and storage rather than external services when possible.

Persist Important Data

Use KV or Object storage for data that needs to persist across flow executions.

Stream Real-Time Events

Use streams for event tracking, analytics, and real-time processing.

Transform Before Agent

Clean and transform data with Functions before passing to agents.

Name Steps Clearly

Use descriptive names: “Store User Preferences” not “Function 1”

Handle Errors

Check function results and handle errors appropriately.

Use Secrets for Credentials

Always use secret-key-get-node for passwords, API keys, and sensitive data.

Modular Architecture

Use function-invoke to break complex logic into reusable functions.

Functions vs. Alternatives

Use Functions when:
  • Need QuivaWorks platform services (streams, storage)
  • Need data transformation (encoding, merging, templates)
  • Want built-in, tested operations
  • Need to persist data across flows
  • Need to orchestrate multiple functions
  • Need to upload files via SFTP
Use Map when:
  • Need to transform data structure
  • Extracting/restructuring objects
  • Functions don’t fit your use case
Use Eval when:
  • Need custom algorithms
  • Complex logic not available
  • Combining multiple operations uniquely
Use External Services when:
  • Specialized service required (e.g., Twilio for SMS)
  • Already using external provider
  • Need features not in QuivaWorks

Troubleshooting

Causes:
  • Wrong function name
  • Typo in function name
Solutions:
  • Check function documentation for exact name
  • Verify function exists: publish-message-to-stream not publish-to-stream
  • Note: Some functions renamed (e.g., JSON-XMLjson-xml)
Causes:
  • Missing required parameter
  • Wrong parameter format
  • Wrong parameter name
Solutions:
  • Review function documentation for exact parameter names
  • Note parameter changes: datavariables (handlebars), key_namekey (secrets)
  • Check that base64 functions take direct input, not wrapped in object
  • Verify variable references
Causes:
  • Stream or bucket doesn’t exist
  • Wrong name
Solutions:
  • Create stream/bucket first
  • Verify exact name
  • Check account has access
Causes:
  • Wrong variable path
  • Function didn’t execute
Solutions:
  • Use ${step_name.result}
  • For base64-decode with JSON, result is auto-parsed
  • For secret-key-get-node, check ${step_name.value} or ${step_name.error}
  • Check execution logs
  • Verify step name matches
Causes:
  • Wrong host or port
  • Network issues
  • Server not responding
Solutions:
  • Verify host and port are correct
  • Check network connectivity
  • Increase connectionTimeout if server is slow
  • Verify credentials are correct

Next Steps