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

Reversible rewards

A reversible reward can be cancelled later: a deleted or voided trade gets its XP and coins back, exactly once, without a ledger rewrite. The mechanism is a bulk update node in reversible mode, where each row is one business event and a cancellation row names the event it reverses.
The API builds and tests that workflow. The cancellation decision stays with your system.

How it works#

Every row in a reversible bulk update is one business event:
RoweventKeyreversesEventKeyAmount columns_op columns
OriginalNew and uniqueblanka non-negative amountadd
CancellationNew and uniquethe original's eventKeyblankblank
The platform stores the effect it actually applied for each original, including any cap, and a cancellation deducts exactly that. Two layers keep it once-only:
the bulk worker skips a repeated original and a second cancellation;
event ingest skips a repeated batch id and a repeated record id before the workflow even runs.
Scope is the community, the workflow and the eventKey. An original and its cancellation must pass through the same workflow.

1. Create the workflow with an ingest trigger#

The record id path is eventKey, so a replayed event never reaches the workflow.

2. Add the bulk step in reversible mode#

The revertible node needs a CSV the workflow builds, one row per event, never one aggregated row per member: an aggregated row cannot be reversed trade by trade.
processingMode: reversible is the switch. identifier is the community's active identifier field, for example email, or a custom identifier when that field is the lookup key.
Reversible rows accept only these headers, case-insensitive: the identifier, eventKey, reversesEventKey, and optionally eventType, account_id, trade_id, tradeStatus, occurredAt, plus Total XP, Total XP_op, Total Coins, Total Coins_op. Any other header fails the whole job. Custom user fields cannot be written by a reversible node, so a second standard-mode step is needed for those.

3. Build the rows#

The CSV is built before the node, and the API builds that builder like any other step: a Code step with its rows bound in options.inputs and its source in options.sourceCode.code.
The Code step emits one CSV row per event, with a stable eventKey derived from the source event, reversesEventKey for a cancellation, and the amount columns.
When account_id or trade_id is present, the original and its cancellation must carry the same values, derived from the same source fields.
A router skips the bulk step when the builder produced no rows.
Create it with POST /{workflowId}/nodes and read the workflow back to confirm what was stored:
A workflow that contains a Code step deploys normally. The one thing to plan for is review: a dry run does not execute source, so the builder shows its inputs and its source but no output, and the bulk step after it cannot run in that dry run. Live-test the Code step on its own with an eventKey you chose, read the output, and only then dry-run the rest. See the playbook Code steps through the API.

4. Test before it pays#

Readback: the bulk step is simulated, and wouldDo carries rowCount, a small sample, the payload format, the processing mode and the identifier. Nothing is uploaded and no job is created.
A Code step in the workflow makes that dry run a partial walk: the builder is simulated with no output, and every step after it is failed with UNRESOLVED_SIMULATED_REFERENCE. Live-test the builder alone first, then read this trace as the evidence for the bulk step and the router.

5. Prove one award and one reversal#

1.
Send a batch with one original event.
2.
Read the run, then the bulk job's status and per-row detail. The row should read applied with the expected change.
3.
Read the member's field value.
4.
Send a second batch with a cancellation row whose reversesEventKey is the original's eventKey.
5.
Read the job detail again: the row should read applied with a negative change equal to what was applied.
6.
Send the same cancellation again: the row should read skipped, and the member's value must not move.
An original resent after it was cancelled reads skipped, not re-awarded. A cancellation whose original was never applied fails as unresolved and changes nothing.

6. Failure handling#

What you seeWhat it meansWhat to do
Job failed, every row unreachableA header the reversible mode does not acceptUse only the documented headers.
Row unresolvedThe cancellation arrived before its original completed, or in a different workflowSend it in a later batch, through the same workflow.
Row skipped on a cancellationA second cancellation of the same originalNothing to do; the ledger is correct.
Row failed with a different-amounts messageThe same original eventKey arrived again with different inputsUse one eventKey per exact reward.
Event ingest skippedA duplicate batch or record idSend a new cancellation eventKey rather than reusing the failed one.
Job-level counts can hide row-level skips: read the per-row detail, not only the job status.

7. Cleanup#

Undeploy and delete as usual. A cancelled original and its cancellation stay in the member's history, which is the record of what happened.

What the API does not cover#

Writing the CSV logic for you. A Code step runs what you wrote; the row shape and the reversal keys are your design.
The decision to cancel. Your system decides and sends the cancellation row.
Rewriting history. Correction of already-paid rewards is a separate, deliberate operation with its own approval.
Modified at 2026-10-28 04:44:15
Previous
Keep a member's tier or role in sync
Next
Test without side effects, then confirm a live run
Built with