1. Workflow Builder
Returning.AI
  • Getting Started
  • Users
    • User directory and provisioning
    • Get Users with Filters
    • Create New User
    • Get User Data
    • Manage User Account
    • Get User Milestones
    • Update User Data, Identifier, And Roles
    • Update User XP and Currency
  • Messaging
    • Agent messaging workflow
    • Get Messages
    • Send Message
    • Reply Message
    • React Message
    • Upload message images
  • Gamification
    • Leaderboards
      • Leaderboards
      • List leaderboards with pagination
      • Create a new leaderboard
      • Update an existing leaderboard
      • Get a single leaderboard by ID
      • Delete a leaderboard
    • Streaks & Mini Games
      • Mini-game State and History
      • List user streak logs
      • List mini-game logs by user email
      • Get current mini-game and streak state
      • Update user spin-wheel information
    • Referral
      • Referral Program Integration
      • Get referral programs
      • Get user's referral summary
    • Rolling Data
    • Match Predictions
      • Create match prediction
      • List match predictions
      • Get match prediction
      • Patch match prediction
      • Publish match prediction
      • Settle match prediction
      • Get settlement results
      • Void match prediction
      • Bulk update match predictions
      • Get bulk job status
      • Get bulk job results
    • Loyalty Points
      • Create loyalty points export
      • Get loyalty points export status
      • Get loyalty points export download link
    • Get tier configuration
    • Get daily user XP and coin changes
    • Search user gamification logs
    • Get user activity stats
  • Rewards & Redemptions
    • Store catalog to redemptions
    • List redemption orders by custom-field identifier
    • Update redemption order status or refund
    • Create redemption order status
    • List redemption orders by user email
    • List redemption statuses
    • Get redemption status by ID
    • List redemption orders by community
    • Get redemption order status history
  • Chart Analysis
    • Create Analysis
    • Get Analysis
    • Update Analysis
    • Delete Analysis
    • List Analyses
    • Append Drawings
  • Bulk Operations
    • Bulk user updates
    • List bulk update jobs
    • Get bulk update job status
    • Get bulk update job details
    • Bulk update users from CSV
    • Bulk update premium currency from CSV
  • Channels
    • Iframe
    • List integration channels
  • Events
    • Outgoing webhooks
      • Encryption
      • User Joins Server
      • User Visits server
      • New Message Posted Anywhere
      • New Message Posted To channel
      • Purchased Store Item
    • Incoming webhooks
      • API Keys & Encryption
      • Send message into channels
      • Update Custom User Fields
      • Update In-game currency
  • Widgets
    • Authenticated Widgets
    • Public widgets
    • Channels
    • Leaderboard
    • Milestone
    • Socials
    • Store
  • Store
    • Store catalog
    • Purchase History
      • Archive or restore an order
      • Update redemption instructions or voucher details
    • Categories
      • List Store categories
      • Create Store category
      • Get Store category by ID
      • Update Store category
      • Delete Store category
    • Products
      • List products
      • Update products in bulk
      • Create products in bulk
      • Create product with vouchers
      • Read product
      • Update product and append vouchers
      • Delete product
    • Redemption-transaction
      • Get redemption transaction detail
    • Get Store configuration
    • Update Store configuration
  • Community Analytics
    • Get Loyalty Overview
    • Get Phone Verification Contacts
  • Community
    • Community directory and appearance
    • Appearance
      • Update community theme colors
      • Update community bot profile
      • Update community URL metadata
      • Update community name and URL
    • Community Users
      • Get community users
      • Get user
    • Create community
  • API Keys
    • API key lifecycle
    • Community API Keys
      • Create API key
      • Read API keys
      • Delete API key
      • Update API key
    • User API Keys
      • List user API keys
      • Create user API key
      • Update user API key
      • Delete user API key
      • Get current API key information
  • User Fields
    • User field definitions and history
    • User Field History
      • Get all user field histories in a community
      • Get user field histories for a specific field
      • Get user field histories for a specific user
      • Get user field histories of specific user field and user
      • Update A User Field Value
      • Deprecated Field-First History Write
      • Deprecated Field-First History Read
    • Get A User Field Definition
    • Update A User Field Definition
    • Create A User Field Definition
    • Delete A User Field Definition
    • List User Field Definitions
  • Legacy
    • Servers
      • Create server
      • List servers
      • Update server metadata
    • Bulk Operations
      • Bulk import users from CSV
    • Authentication
      • Secure Auth
      • Register user with password
      • Verify user email
      • Log in user with password
    • Badges
      • List badges
      • Create badge
      • Update badge
      • Delete badge
      • Remove badge from user
      • Award badge to user
    • Messaging
    • Roles & Permissions
      • List server roles
      • Create role
      • Update role
      • Delete role
      • List user roles
      • Add role to user
      • Remove role from user
    • Users
      • Get user
      • Upload user avatar
    • Channels
      • Create channel
      • Update channel
      • Delete channel
    • API Keys
      • List integration API keys
      • Create integration API key
      • Delete integration API key
      • Update integration API key
  • Data Workflows
    • Read event-ingest lifecycle status by trigger and batch ID.
  • Community Logs
    • Retrieve and export community logs
  • Workflow Builder
    • Workflow Builder API overview
    • Connect an AI agent to the Workflow Builder tools
    • Bind step inputs to trigger and earlier-step outputs
    • Code steps through the API
    • Edit safely: revisions, conflicts, export, import and copying a workflow
    • Set up an event-ingest workflow and check batch status
    • Keep a member's tier or role in sync
    • Reversible rewards
    • Test without side effects, then confirm a live run
    • Build a trading-rewards workflow from event ingest
    • Reward members from your own system with a webhook workflow
    • List step types and trigger types
      GET
    • List workflows
      GET
    • Create a workflow
      POST
    • Get a workflow
      GET
    • Rename a workflow or set its failure webhook
      PATCH
    • Delete a workflow
      DELETE
    • Duplicate a workflow
      POST
    • Export a workflow definition
      GET
    • Validate a stored workflow
      POST
    • Create or replace the trigger
      PUT
    • Add a step
      POST
    • Get a step
      GET
    • Update a step
      PATCH
    • Delete a step
      DELETE
    • Reorder a main-line step
      POST
    • Duplicate a step
      POST
    • Add a router branch
      POST
    • Update a router branch
      PATCH
    • Delete a router branch
      DELETE
    • Duplicate a router branch
      POST
    • Test one step
      POST
    • Test a whole workflow
      POST
    • Deploy a workflow
      POST
    • Undeploy a workflow
      POST
    • List the runs of a workflow
      GET
    • Get one run
      GET
    • Retry a failed run
      POST
    • Call the workflow tools over MCP
      POST
  • Schemas
    • Sample Schemas
    • Schemas
    • Outgoing webhooks
    • Analysis
    • Pet
    • Category
    • Tag
    • ValidationError
    • NotFoundError
    • InternalServerError
    • NotImplementedError
    • CreateUserFieldHistoryResponse
    • CreateUserFieldHistorySuccessResponse
    • UserFieldHistoryItem
    • GetUserFieldHistoriesResponse
    • UserFieldHistoriesValidationError
    • UserFieldHistoriesMetaWithValidation
    • UserFieldHistoriesMetaWithPagination
    • GetUserFieldHistoriesSuccessResponse
    • CreateUserFieldResponse
    • CreateUserFieldSuccessResponse
    • DeleteUserFieldResponse
    • DeleteUserFieldSuccessResponse
    • UserFieldCreator
    • GetUserFieldResponse
    • GetUserFieldSuccessResponse
    • ValidationErrorItem
    • GetUserFieldsMetaResponse
    • CreatorInfo
    • UserFieldResponse
    • GetUserFieldsSuccessResponse
    • UpdateUserFieldResponse
    • UpdateUserFieldPayload
    • UpdateUserFieldSuccessResponse
    • MetaResponse
    • GetUserResponse
    • GetUserSuccessResponse
    • Purchased store item
    • ErrorResponse
    • New message posted to channel
    • UpdateAnalysisRequest
    • User visits server
    • AppendDrawingsRequest
    • User join server
    • CreateAnalysisResponse
    • GetAnalysisResponse
    • UpdateAnalysisResponse
    • AppendDrawingsResponse
    • AnalysisMetadata
    • Expiry
    • Levels
    • LevelEntry
    • Drawing
    • HorizontalLineDrawing
    • LineDrawing
    • RectangleDrawing
    • ParallelDrawing
    • FibonacciRetracementDrawing
    • Coordinate
    • DrawingStyle
    • AnalysisDetail
    • AnalysisSummary
    • CreateAnalysisRequest
    • ListAnalysesResponse
    • StandardApiError
    • StandardSuccessEnvelope
    • PurchasedStoreItemEvent
    • ChannelMessagePostedEvent
    • UserVisitedCommunityEvent
    • UserJoinedCommunityEvent
  1. Workflow Builder

Build a trading-rewards workflow from event ingest

A trading-rewards pipeline takes broker trade events, aggregates them per trader per cycle, and pays a reward for the volume. The workflow's job is the last part: receive one aggregated batch, calculate the reward for each row, and apply it.
The API builds, tests, deploys and monitors that workflow, including the reward calculation: a Code step is a normal step type here, and it can be created, changed, tested and deployed like any other. Gathering the trades, aggregating them, and the decision of what the policy should be are your side.

What you end up with#

1.
An event ingest workflow with a batch id path and per-row record id paths.
2.
A read step that resolves each trader from the aggregated row.
3.
A reward write step, in a branch that only runs when the row is eligible.
4.
A live workflow, one canary batch, one run read back, and the per-row result.

Where the reward calculation goes#

Most real reward policies are a calculation: exact instrument, category rate, rounding, a cap, a skip reason per row. There are two places to put it, and both are fully supported:
PartWhere it is built
Collector, aggregation, deterministic identitiesYour system
Reward calculationA Code step in the workflow, or your own system before the event is sent
Ingest trigger, read step, router, bulk-update or write stepThe API
Deploy, confirming a run, run readsThe API
A Code step in the workflow keeps the policy next to the payout. Create it with POST /{workflowId}/nodes and type: "code", with options.inputs bound to the row ({{<triggerId>.csv}}, {{<readStepId>.Total XP}}) and the source in options.sourceCode.code. Its result is keyed by the names it returns, so the bulk step references {{<codeStepId>.csv}}. It can be changed, duplicated, imported and tested like any other step, and a workflow containing it deploys normally.
What a Code step costs you in review: a dry run does not execute source, so it shows the resolved inputs and the source but not the output, and the step after it cannot run in that dry run (it fails with UNRESOLVED_SIMULATED_REFERENCE). Live-test the Code step on its own with a seed you chose, read the output, and only then dry-run the rest around it. Details are in the playbook Code steps through the API.
Your own system keeps the workflow Code-free: send the calculated amount per row, and the workflow's job is delivery. That is simpler to review, and it puts the policy in code you already test.
Either is fine. Choose by where you want the policy to live, not by what the API accepts.

1. Fix the delivery identity and the event contract#

Before any call, decide:
The delivery identity. One field per pipeline: a stable broker customer id when the broker supplies one and registration writes the same value, otherwise a normalised email. Never both inside one pipeline.
The aggregation unit. One row per trader per cycle, with the volume facts preserved per instrument. The workflow does not group; grouping has to happen before the batch arrives.
The batch id path and the per-row record id path. These are the two deduplication layers, and they are configuration on the trigger.
The reward rule and its owner. Rates, rounding and caps belong to the workflow's configuration, not to the sender's payload.
The cutoff. Which events are eligible. If a backlog exists before launch, decide explicitly whether it is paid or discarded.

2. Read the catalog, then create the workflow#

Take every field key from the catalog rather than guessing one: GET /catalog returns platformActionFields.get and platformActionFields.post, each entry carrying the key the step stores, the label the platform stores beside it, and whether the field is builtin or custom.
Create the workflow with an event ingest trigger. The batch id path is read from the root of the delivered event, and record id paths are read from each row:
Readback: 201, status: draft, trigger.type: event-ingest, the two paths stored under trigger.options, and a revision.
The trigger id (trigger._id) is what the next steps reference. The production ingest id a sender needs is the trigger's id; give the sender that value, plus the endpoint it posts to.

3. Add the steps#

A read step that resolves the trader from the aggregated row. total_xp and total_coins are the read keys the catalog returns; a custom field would appear in the same list:
A router that keeps ineligible rows out of the reward step. The condition reads the earlier step's output, so a trader the read step could not resolve never reaches the reward:
The reward step. xp is the write key from the catalog's post list. Two shapes are supported:
A per-trader write with post-user-fields, which is simple and needs no file:
A bulk update from a CSV the workflow builds, which is the shape a high-volume pipeline needs:
The bulk step queues a separate job, so the workflow's run status is not the reward's outcome. Read the job with the platform's bulk update endpoints, and keep its log name unique per batch so a job can be matched to the batch that produced it.

4. Validate and dry-run#

Readback: the trace names the branch taken, and the reward step is simulated with the resolved member, field and amount. sideEffects: "none" proves nothing was paid.
If the workflow carries a Code step, the dry run is a partial walk: the Code step is simulated with its source and no output, and every step after it fails with UNRESOLVED_SIMULATED_REFERENCE. Test the Code step live on its own first, then read the trace here as evidence for everything around it.
Run at least two dry runs: one eligible row and one row that must not pay.

5. Deploy and prove one canary cycle#

Then send one bounded batch from your collector, with a fresh batch id and fresh record ids, and read it back in three places:
1.
GET /{workflowId}/runs for the run, then GET /runs/{runId} for the per-step result.
2.
The bulk update job, when the reward step is a bulk step: status, then per-row detail, then the member's own field value.
3.
Your own ledger: the batch should be acknowledged once, and a replay of the same batch must not pay again.
success on the run is not the reward. The member's field value, or the bulk job's per-row result, is the reward. Say "paid" only when you have one of those.

6. Failure handling#

What you seeWhat it meansWhat to do
Ingest rejected with a batch id path messageThe batch id was not at the configured path in the root of the eventFix the sender's envelope; keep the same batch id only for a byte-identical retry.
Ingest skippedA duplicate batch id, or every row was a duplicateDo not resend under a new batch id unless the data really is new.
Run errorA step failed; the run detail names itFix the step, then decide about the batch.
Run success, member unchangedThe reward step was skipped or the amount was zeroRead the run detail and the branch that ran.
Bulk job Failed with every row successThe job failed as a whole; nothing was appliedCheck the CSV header against the community's identifier field, then resend as a new batch.
Two awards for one rowThe row reached the reward step twiceFix the record id path or the sender's aggregation before the next cycle.
Retrying a failed run re-executes the whole workflow, so a retry after a partial payment can pay twice. Read the member's value before retrying. A new batch or aggregate id alone is not a safe financial correction: on a trigger with recordIdPaths, a new batch to the same workflow only pays rows whose record ids are new (a duplicated workflow is a new workflow, so its first batch pays every row again), so correct an amount already paid through your approved correction or compensation path, as described in Trading volume and rewards.

7. Cleanup#

Undeploy, then delete, exactly as in the webhook playbook. Keep the batch ids and job names from your canary in your own record: they are the evidence that the pipeline worked.

What the API does not cover#

The collector, its cursor and its overlap window.
Aggregation by the delivery identity, and the choice between a customer id and an email.
Judging whether the reward policy is right. A Code step runs what you wrote; it does not tell you whether the rule is the one you meant.
The reward policy decision itself. Sending a calculated amount from your own system is the API-only alternative.
A recurring schedule for the collector.
Modified at 2026-10-28 04:44:36
Previous
Test without side effects, then confirm a live run
Next
Reward members from your own system with a webhook workflow
Built with