Skip to content

Manage Rule Engine policies

Configure drafts, simulate decisions, publish policies, and retain version history.

Use this guide when your application manages policy configuration through the API. Teams can also edit, simulate, and publish policies in the Client Dashboard. Application developers consuming decisions can start with Rule Engine integration.

Find your policies

CryptoSwift maintains one INCOMING and one OUTGOING policy per tenant. Each policy has an editable draft, an active published rule set, and immutable published versions.

List both policies and save the returned id for the scope you want to manage. This example tenant already has published policies. We will update its outgoing policy from version 2 to 3:

curl --location 'https://api-dev.cryptoswift.eu/rule-engine' \
  --header "X-Api-Key: $API_KEY"

Retrieve one policy with GET /rule-engine/{id}. The response includes its scope, draftRules, publishedRules, publishedVersion, latest publish comment, and whether it has an unpublished draft.

Define a draft

Rules are evaluated from top to bottom and the first enabled matching rule wins. Every rule set must contain exactly one enabled fallback rule with empty all and any arrays, and that rule must be last.

curl --request PATCH 'https://api-dev.cryptoswift.eu/rule-engine/{ruleEngineId}/draft' \
  --header "X-Api-Key: $API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "draftRules": [
      {
        "id": "high-amount-wait",
        "name": "Wait for large transfers",
        "enabled": true,
        "when": {
          "all": [
            { "field": "amount", "operator": "GTE", "value": 10000, "currency": "USD" }
          ],
          "any": []
        },
        "then": {
          "decision": "WAIT",
          "waitForSeconds": 120,
          "onTimeoutDecision": "REVIEW"
        }
      },
      {
        "id": "default",
        "name": "Default",
        "enabled": true,
        "when": { "all": [], "any": [] },
        "then": { "decision": "PROCEED" }
      }
    ]
  }'

Condition fields are status, riskSeverity, riskScore, amount, hasTxHash, counterpartyEntityId, and counterpartyEntityCountry. Operators are EQ, NEQ, GT, GTE, LT, LTE, IN, NOT_IN, CONTAINS, STARTS_WITH, ENDS_WITH, EXISTS, and NOT_EXISTS.

Within when, every condition in all must match, while at least one condition in a non-empty any array must match. Country values use uppercase ISO 3166-1 alpha-2 codes. An amount condition can specify USD or EUR as its currency.

Actions are PROCEED, WAIT, REVIEW, and BLOCK. A WAIT action also requires waitForSeconds from 1 to 86,400 and an onTimeoutDecision of PROCEED, REVIEW, or BLOCK.

Simulate before publishing

Simulation is read-only and returns the decision, matched rule, and a per-rule evaluation trace. Use DRAFT with the rules you are editing, or PUBLISHED to test the active version.

curl --request POST 'https://api-dev.cryptoswift.eu/rule-engine/{ruleEngineId}/simulate' \
  --header "X-Api-Key: $API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "source": "DRAFT",
  "input": {
    "status": "DELIVERED",
    "riskScore": 25,
    "riskSeverity": "low",
    "amount": 12000,
    "amountCurrency": "USD",
    "hasTxHash": false
  },
  "draftRules": [
    {
      "id": "high-amount-wait",
      "name": "Wait for large transfers",
      "enabled": true,
      "when": {
        "all": [
          {
            "field": "amount",
            "operator": "GTE",
            "value": 10000,
            "currency": "USD"
          }
        ],
        "any": []
      },
      "then": {
        "decision": "WAIT",
        "waitForSeconds": 120,
        "onTimeoutDecision": "REVIEW"
      }
    },
    {
      "id": "default",
      "name": "Default",
      "enabled": true,
      "when": {
        "all": [],
        "any": []
      },
      "then": {
        "decision": "PROCEED"
      }
    }
  ]
}'

This request simulates the draft you just edited. Include the complete draftRules array for source: "DRAFT"; source: "PUBLISHED" instead evaluates the active published rules. The draft has not been published yet, so ruleEngineVersion still reports the current published version, 2.

Publish and retain version history

Publishing activates the current draft, increments publishedVersion, and creates an immutable snapshot:

curl --request POST 'https://api-dev.cryptoswift.eu/rule-engine/{ruleEngineId}/publish' \
  --header "X-Api-Key: $API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{ "comment": "Large transfer review policy" }'

Read the published result on a transaction

After publication, new evaluations use version 3. For example, an outgoing transaction with amountUsd: 35000 matches high-amount-wait and returns the following result in its transaction response. The same ruleEngine structure is available in create responses and transaction webhooks.

curl --location 'https://api-dev.cryptoswift.eu/transactions/233e3fd4-2ef0-477c-a398-8f993d131a19' \
  --header "X-Api-Key: $API_KEY"

Follow decision handling to apply the result and enforce the waiting deadline in your backend.

Version history and rollback

Use these endpoints for change review and rollback:

EndpointPurpose
GET /rule-engine/{id}/versionsList published versions and their comments.
GET /rule-engine/{id}/versions/{version}Retrieve the complete immutable rules snapshot.
POST /rule-engine/{id}/restoreCopy a previous version into the draft with { "version": 3 }.

Restoring does not activate the old policy immediately. Simulate the restored draft, then publish it to make it active.

Next steps