POST · Simuler

Workflows : Simuler. Paramètres, accès et exemples de réponse.

Rédigé par Red Blue

Mis à jour le

Workflows

POST /api/v1/workflows/simulate

operationId : workflow_simulate

Accès

Permission

Consentements OAuth

OAuth : délégation d’un équipier pour l’API

workflow.update

api:connect, workflow:write

KHONY_ORIGIN est l’origine HTTPS de votre application Khony, sans chemin final. Remplacez les identifiants de l’exemple par ceux de vos ressources autorisées. Les données de réponse ci-dessous illustrent le format ; elles ne sont pas le résultat d’un appel à votre organisation.

Champs du corps JSON

Nom

Emplacement

Requis

Type et contraintes

productId

JSON

Oui

string

definition

JSON

Oui

object

trigger

JSON

Oui

Voir le schéma complet

nodeOutputs

JSON

Non

object

routeOverrides

JSON

Non

object

fragmentCursor

JSON

Non

string ; Longueur maximale : 2048

Exemple de requête

Shell
curl --request POST "$KHONY_ORIGIN/api/v1/workflows/simulate" \
  --header "Authorization: Bearer $KHONY_ACCESS_TOKEN" \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "productId": "product_01k3w8d7vhe008000000000001",
  "definition": {
    "schemaVersion": 1,
    "trigger": {
      "id": "start",
      "kind": "trigger",
      "definitionKey": "khony.feedback.created",
      "definitionVersion": 1,
      "config": {
        "sourceIn": [
          "widget"
        ]
      }
    },
    "nodes": [
      {
        "id": "finish",
        "kind": "end",
        "label": "Done",
        "outcome": "succeeded",
        "result": {}
      }
    ],
    "edges": [
      {
        "id": "end",
        "sourceNodeId": "start",
        "sourcePort": "next",
        "targetNodeId": "finish",
        "targetPort": "input"
      }
    ],
    "settings": {
      "timezone": "UTC",
      "allowWorkflowOriginEvents": false,
      "maxChainDepth": 32,
      "maxConcurrentRuns": 20
    }
  },
  "trigger": {}
}'
Shell

Réponse de succès · HTTP 200

JSON
{
  "kind": "simulation",
  "jsonFragment": "{\"success\":true,\"diagnostics\":[],\"simulation\":{\"steps\":[{\"nodeId\":\"finish\",\"kind\":\"end\",\"routePort\":null,\"output\":{},\"effect\":\"not_executed\"}],\"context\":{\"trigger\":{},\"nodes\":{\"finish\":{}}},\"completed\":true}}",
  "sha256": "780fad2003bcf128bd3226e4ee79782ad7b77c233660d26542a861d590826fea",
  "totalBytes": 208,
  "nextFragmentCursor": null
}
JSON
Schéma complet du corps JSON
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "productId": {
      "type": "string",
      "pattern": "^product_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
    },
    "definition": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "type": "number",
          "const": 1
        },
        "trigger": {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "trigger"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema3"
            },
            "config": {
              "default": {},
              "$ref": "#/$defs/__schema4"
            }
          },
          "required": [
            "id",
            "kind",
            "definitionKey",
            "definitionVersion"
          ],
          "additionalProperties": false
        },
        "nodes": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema6"
          }
        },
        "edges": {
          "minItems": 1,
          "maxItems": 150,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema35"
          }
        },
        "settings": {
          "default": {
            "timezone": "UTC",
            "allowWorkflowOriginEvents": false,
            "maxChainDepth": 32,
            "maxConcurrentRuns": 20
          },
          "type": "object",
          "properties": {
            "conversationControl": {
              "type": "string",
              "const": "exclusive_reply"
            },
            "timezone": {
              "default": "UTC",
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "allowWorkflowOriginEvents": {
              "default": false,
              "type": "boolean"
            },
            "maxChainDepth": {
              "default": 32,
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "maxConcurrentRuns": {
              "default": 20,
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          },
          "additionalProperties": false
        },
        "editor": {
          "type": "object",
          "properties": {
            "nodes": {
              "default": {},
              "type": "object",
              "propertyNames": {
                "$ref": "#/$defs/__schema0"
              },
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "x": {
                    "type": "number"
                  },
                  "y": {
                    "type": "number"
                  }
                },
                "required": [
                  "x",
                  "y"
                ],
                "additionalProperties": false
              }
            },
            "viewport": {
              "type": "object",
              "properties": {
                "x": {
                  "type": "number"
                },
                "y": {
                  "type": "number"
                },
                "zoom": {
                  "type": "number",
                  "minimum": 0.05,
                  "maximum": 4
                }
              },
              "required": [
                "x",
                "y",
                "zoom"
              ],
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        }
      },
      "required": [
        "schemaVersion",
        "trigger",
        "nodes",
        "edges"
      ],
      "additionalProperties": false
    },
    "trigger": {
      "$ref": "#/$defs/__schema5"
    },
    "nodeOutputs": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema5"
      }
    },
    "routeOverrides": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "type": "string"
      }
    },
    "fragmentCursor": {
      "type": "string",
      "maxLength": 2048
    }
  },
  "required": [
    "productId",
    "definition",
    "trigger"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{1,63}$"
    },
    "__schema1": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "__schema2": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_.-]{2,127}$"
    },
    "__schema3": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema4": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema5"
      }
    },
    "__schema5": {
      "anyOf": [
        {
          "type": [
            "string",
            "number",
            "boolean",
            "null"
          ]
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema5"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema5"
          }
        }
      ]
    },
    "__schema6": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "condition"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "expression": {
              "$ref": "#/$defs/__schema7"
            }
          },
          "required": [
            "id",
            "kind",
            "expression"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "$ref": "#/$defs/__schema19"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "cases": {
              "$ref": "#/$defs/__schema20"
            }
          },
          "required": [
            "id",
            "kind",
            "cases"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "action"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema3"
            },
            "input": {
              "default": {},
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema23"
              }
            },
            "policy": {
              "default": {
                "timeoutSeconds": 30,
                "retry": {
                  "maxAttempts": 3,
                  "initialDelaySeconds": 5,
                  "maxDelaySeconds": 300,
                  "backoff": "exponential",
                  "jitter": true
                },
                "onError": {
                  "strategy": "fail_workflow"
                }
              },
              "type": "object",
              "properties": {
                "timeoutSeconds": {
                  "default": 30,
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 3600
                },
                "retry": {
                  "default": {
                    "maxAttempts": 3,
                    "initialDelaySeconds": 5,
                    "maxDelaySeconds": 300,
                    "backoff": "exponential",
                    "jitter": true
                  },
                  "type": "object",
                  "properties": {
                    "maxAttempts": {
                      "$ref": "#/$defs/__schema24"
                    },
                    "initialDelaySeconds": {
                      "$ref": "#/$defs/__schema25"
                    },
                    "maxDelaySeconds": {
                      "$ref": "#/$defs/__schema26"
                    },
                    "backoff": {
                      "$ref": "#/$defs/__schema27"
                    },
                    "jitter": {
                      "$ref": "#/$defs/__schema28"
                    }
                  },
                  "additionalProperties": false
                },
                "onError": {
                  "default": {
                    "strategy": "fail_workflow"
                  },
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "strategy": {
                          "type": "string",
                          "const": "fail_workflow"
                        }
                      },
                      "required": [
                        "strategy"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "strategy": {
                          "type": "string",
                          "const": "continue"
                        }
                      },
                      "required": [
                        "strategy"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "strategy": {
                          "type": "string",
                          "const": "route_error"
                        }
                      },
                      "required": [
                        "strategy"
                      ],
                      "additionalProperties": false
                    }
                  ]
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "id",
            "kind",
            "definitionKey",
            "definitionVersion"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "$ref": "#/$defs/__schema29"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "mode": {
              "$ref": "#/$defs/__schema30"
            },
            "durationSeconds": {
              "$ref": "#/$defs/__schema31"
            },
            "until": {
              "$ref": "#/$defs/__schema32"
            }
          },
          "required": [
            "id",
            "kind",
            "mode"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "wait_event"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema3"
            },
            "config": {
              "default": {},
              "$ref": "#/$defs/__schema4"
            },
            "correlation": {
              "type": "object",
              "propertyNames": {
                "$ref": "#/$defs/__schema33"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema10"
              }
            },
            "timeoutSeconds": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31536000
            }
          },
          "required": [
            "id",
            "kind",
            "definitionKey",
            "definitionVersion",
            "correlation",
            "timeoutSeconds"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "approval"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "title": {
              "$ref": "#/$defs/__schema10"
            },
            "message": {
              "$ref": "#/$defs/__schema10"
            },
            "requiredPermissions": {
              "minItems": 1,
              "maxItems": 20,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema34"
              }
            },
            "timeoutSeconds": {
              "type": "integer",
              "minimum": 60,
              "maximum": 7776000
            }
          },
          "required": [
            "id",
            "kind",
            "title",
            "requiredPermissions",
            "timeoutSeconds"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema0"
            },
            "kind": {
              "type": "string",
              "const": "end"
            },
            "label": {
              "$ref": "#/$defs/__schema1"
            },
            "outcome": {
              "type": "string",
              "enum": [
                "succeeded",
                "stopped"
              ]
            },
            "result": {
              "default": {},
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema23"
              }
            }
          },
          "required": [
            "id",
            "kind",
            "outcome"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema7": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "$ref": "#/$defs/__schema8"
            },
            "operator": {
              "$ref": "#/$defs/__schema9"
            },
            "left": {
              "$ref": "#/$defs/__schema10"
            },
            "right": {
              "$ref": "#/$defs/__schema18"
            }
          },
          "required": [
            "kind",
            "operator",
            "left"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "all"
            },
            "expressions": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema7"
              }
            }
          },
          "required": [
            "kind",
            "expressions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "any"
            },
            "expressions": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema7"
              }
            }
          },
          "required": [
            "kind",
            "expressions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "not"
            },
            "expression": {
              "$ref": "#/$defs/__schema7"
            }
          },
          "required": [
            "kind",
            "expression"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema8": {
      "type": "string",
      "const": "comparison"
    },
    "__schema9": {
      "type": "string",
      "enum": [
        "equals",
        "not_equals",
        "greater_than",
        "greater_than_or_equal",
        "less_than",
        "less_than_or_equal",
        "contains",
        "starts_with",
        "ends_with",
        "in",
        "exists",
        "not_exists"
      ]
    },
    "__schema10": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "literal"
            },
            "value": {
              "$ref": "#/$defs/__schema5"
            }
          },
          "required": [
            "kind",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/__schema11"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "template"
            },
            "parts": {
              "minItems": 1,
              "maxItems": 100,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema17"
              }
            }
          },
          "required": [
            "kind",
            "parts"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema11": {
      "type": "object",
      "properties": {
        "kind": {
          "$ref": "#/$defs/__schema12"
        },
        "source": {
          "$ref": "#/$defs/__schema13"
        },
        "nodeId": {
          "$ref": "#/$defs/__schema14"
        },
        "path": {
          "$ref": "#/$defs/__schema15"
        }
      },
      "required": [
        "kind",
        "source"
      ],
      "additionalProperties": false
    },
    "__schema12": {
      "type": "string",
      "const": "reference"
    },
    "__schema13": {
      "type": "string",
      "enum": [
        "trigger",
        "node"
      ]
    },
    "__schema14": {
      "$ref": "#/$defs/__schema0"
    },
    "__schema15": {
      "default": [],
      "maxItems": 32,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema16"
      }
    },
    "__schema16": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "__schema17": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 10000
        },
        {
          "$ref": "#/$defs/__schema11"
        }
      ]
    },
    "__schema18": {
      "$ref": "#/$defs/__schema10"
    },
    "__schema19": {
      "type": "string",
      "const": "decision"
    },
    "__schema20": {
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema21"
      }
    },
    "__schema21": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema22"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "when": {
          "$ref": "#/$defs/__schema7"
        }
      },
      "required": [
        "id",
        "label",
        "when"
      ],
      "additionalProperties": false
    },
    "__schema22": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{0,63}$"
    },
    "__schema23": {
      "anyOf": [
        {
          "$ref": "#/$defs/__schema10"
        },
        {
          "maxItems": 1000,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema23"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema23"
          }
        }
      ]
    },
    "__schema24": {
      "default": 3,
      "type": "integer",
      "minimum": 1,
      "maximum": 20
    },
    "__schema25": {
      "default": 5,
      "type": "integer",
      "minimum": 1,
      "maximum": 86400
    },
    "__schema26": {
      "default": 300,
      "type": "integer",
      "minimum": 1,
      "maximum": 604800
    },
    "__schema27": {
      "default": "exponential",
      "type": "string",
      "enum": [
        "fixed",
        "exponential"
      ]
    },
    "__schema28": {
      "default": true,
      "type": "boolean"
    },
    "__schema29": {
      "type": "string",
      "const": "delay"
    },
    "__schema30": {
      "type": "string",
      "enum": [
        "duration",
        "until"
      ]
    },
    "__schema31": {
      "type": "integer",
      "minimum": 1,
      "maximum": 31536000
    },
    "__schema32": {
      "$ref": "#/$defs/__schema10"
    },
    "__schema33": {
      "type": "string"
    },
    "__schema34": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_.:-]{2,127}$"
    },
    "__schema35": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema0"
        },
        "sourceNodeId": {
          "$ref": "#/$defs/__schema0"
        },
        "sourcePort": {
          "$ref": "#/$defs/__schema22"
        },
        "targetNodeId": {
          "$ref": "#/$defs/__schema0"
        },
        "targetPort": {
          "default": "input",
          "$ref": "#/$defs/__schema22"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "order": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000
        }
      },
      "required": [
        "id",
        "sourceNodeId",
        "sourcePort",
        "targetNodeId"
      ],
      "additionalProperties": false
    }
  }
}
JSON
Schéma complet de la réponse
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "kind": {
      "type": "string",
      "const": "simulation"
    },
    "jsonFragment": {
      "type": "string",
      "maxLength": 24576
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "totalBytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "nextFragmentCursor": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 2048
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "kind",
    "jsonFragment",
    "sha256",
    "totalBytes",
    "nextFragmentCursor"
  ],
  "additionalProperties": false
}
JSON

Refus et reprise

Les statuts documentés pour cette opération sont 400, 401, 402, 403, 404, 409, 428, 429, 500, 503. Identifiez la cause avec error.code et, lorsqu’il est présent, error.reason. Une réponse 409 peut demander une relecture de révision ou signaler une commande incompatible ; une réponse 428 demande une confirmation humaine. Ne rejouez une écriture que selon son contrat.

Notes du contrat
JSON
{
  "description": "Requires a dedicated API OAuth bearer for audience /api/v1, api:connect and the stated workflow scope, current organization/product consent and native human permissions. Organization keys and cookies are not accepted. Every admission consumes a product API request; native write billing checks apply. Requires the complete native canonical definition. Outputs use supplied nodeOutputs; every effect remains not_executed. This is not a live run or provider test. Concatenate jsonFragment values using nextFragmentCursor, then parse once, as with workflow_read."
}
JSON