POST · Enregistrer une définition

Workflows : Enregistrer une définition. Paramètres, accès et exemples de réponse.

Rédigé par Red Blue

Mis à jour le

Workflows

POST /api/v1/workflows/canonical

operationId : workflow_canonical_write

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.

Paramètres et en-têtes

Nom

Emplacement

Requis

Type et contraintes

idempotency-key

header

Oui

string ; uuid

x-khony-confirmation

header

Non

string ; uuid

Champs du corps JSON

Nom

Emplacement

Requis

Type et contraintes

productId

JSON

Oui

string

request

JSON

Oui

object

Variantes de la requête

Sélecteur

Valeur

Autres champs requis dans request

request.kind

"create"

name, definition

request.kind

"save"

workflowId, expectedRevision, definition

Choisissez une variante et respectez son schéma complet : les contraintes des champs optionnels et les unions imbriquées restent applicables.

Exemple de requête

Shell
curl --request POST "$KHONY_ORIGIN/api/v1/workflows/canonical" \
  --header "Authorization: Bearer $KHONY_ACCESS_TOKEN" \
  --header 'idempotency-key: 0198f886-9f71-7000-8000-000000000010' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "productId": "product_01k3w8d7vhe008000000000001",
  "request": {
    "kind": "create",
    "name": "Canonical workflow",
    "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
      }
    }
  }
}'
Shell

Réponse de succès · HTTP 200

JSON
{
  "workflowId": "workflow_01k3w8d7vhe008000000000001",
  "revision": 0
}
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}$"
    },
    "request": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "create"
            },
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 160
            },
            "definition": {
              "$ref": "#/$defs/__schema0"
            }
          },
          "required": [
            "kind",
            "name",
            "definition"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "save"
            },
            "workflowId": {
              "type": "string",
              "pattern": "^workflow_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
            },
            "expectedRevision": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "definition": {
              "$ref": "#/$defs/__schema0"
            }
          },
          "required": [
            "kind",
            "workflowId",
            "expectedRevision",
            "definition"
          ],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [
    "productId",
    "request"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "schemaVersion": {
          "type": "number",
          "const": 1
        },
        "trigger": {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "trigger"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema3"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema4"
            },
            "config": {
              "default": {},
              "$ref": "#/$defs/__schema5"
            }
          },
          "required": [
            "id",
            "kind",
            "definitionKey",
            "definitionVersion"
          ],
          "additionalProperties": false
        },
        "nodes": {
          "minItems": 1,
          "maxItems": 100,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema7"
          }
        },
        "edges": {
          "minItems": 1,
          "maxItems": 150,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema36"
          }
        },
        "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/__schema1"
              },
              "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
    },
    "__schema1": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{1,63}$"
    },
    "__schema2": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "__schema3": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_.-]{2,127}$"
    },
    "__schema4": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 9007199254740991
    },
    "__schema5": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema6"
      }
    },
    "__schema6": {
      "anyOf": [
        {
          "type": [
            "string",
            "number",
            "boolean",
            "null"
          ]
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema6"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema6"
          }
        }
      ]
    },
    "__schema7": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "condition"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "expression": {
              "$ref": "#/$defs/__schema8"
            }
          },
          "required": [
            "id",
            "kind",
            "expression"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "$ref": "#/$defs/__schema20"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "cases": {
              "$ref": "#/$defs/__schema21"
            }
          },
          "required": [
            "id",
            "kind",
            "cases"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "action"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema3"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema4"
            },
            "input": {
              "default": {},
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema24"
              }
            },
            "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/__schema25"
                    },
                    "initialDelaySeconds": {
                      "$ref": "#/$defs/__schema26"
                    },
                    "maxDelaySeconds": {
                      "$ref": "#/$defs/__schema27"
                    },
                    "backoff": {
                      "$ref": "#/$defs/__schema28"
                    },
                    "jitter": {
                      "$ref": "#/$defs/__schema29"
                    }
                  },
                  "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/__schema1"
            },
            "kind": {
              "$ref": "#/$defs/__schema30"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "mode": {
              "$ref": "#/$defs/__schema31"
            },
            "durationSeconds": {
              "$ref": "#/$defs/__schema32"
            },
            "until": {
              "$ref": "#/$defs/__schema33"
            }
          },
          "required": [
            "id",
            "kind",
            "mode"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "wait_event"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "definitionKey": {
              "$ref": "#/$defs/__schema3"
            },
            "definitionVersion": {
              "$ref": "#/$defs/__schema4"
            },
            "config": {
              "default": {},
              "$ref": "#/$defs/__schema5"
            },
            "correlation": {
              "type": "object",
              "propertyNames": {
                "$ref": "#/$defs/__schema34"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema11"
              }
            },
            "timeoutSeconds": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31536000
            }
          },
          "required": [
            "id",
            "kind",
            "definitionKey",
            "definitionVersion",
            "correlation",
            "timeoutSeconds"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "approval"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "title": {
              "$ref": "#/$defs/__schema11"
            },
            "message": {
              "$ref": "#/$defs/__schema11"
            },
            "requiredPermissions": {
              "minItems": 1,
              "maxItems": 20,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema35"
              }
            },
            "timeoutSeconds": {
              "type": "integer",
              "minimum": 60,
              "maximum": 7776000
            }
          },
          "required": [
            "id",
            "kind",
            "title",
            "requiredPermissions",
            "timeoutSeconds"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "id": {
              "$ref": "#/$defs/__schema1"
            },
            "kind": {
              "type": "string",
              "const": "end"
            },
            "label": {
              "$ref": "#/$defs/__schema2"
            },
            "outcome": {
              "type": "string",
              "enum": [
                "succeeded",
                "stopped"
              ]
            },
            "result": {
              "default": {},
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {
                "$ref": "#/$defs/__schema24"
              }
            }
          },
          "required": [
            "id",
            "kind",
            "outcome"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema8": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "$ref": "#/$defs/__schema9"
            },
            "operator": {
              "$ref": "#/$defs/__schema10"
            },
            "left": {
              "$ref": "#/$defs/__schema11"
            },
            "right": {
              "$ref": "#/$defs/__schema19"
            }
          },
          "required": [
            "kind",
            "operator",
            "left"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "all"
            },
            "expressions": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema8"
              }
            }
          },
          "required": [
            "kind",
            "expressions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "any"
            },
            "expressions": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema8"
              }
            }
          },
          "required": [
            "kind",
            "expressions"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "not"
            },
            "expression": {
              "$ref": "#/$defs/__schema8"
            }
          },
          "required": [
            "kind",
            "expression"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema9": {
      "type": "string",
      "const": "comparison"
    },
    "__schema10": {
      "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"
      ]
    },
    "__schema11": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "literal"
            },
            "value": {
              "$ref": "#/$defs/__schema6"
            }
          },
          "required": [
            "kind",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/__schema12"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "template"
            },
            "parts": {
              "minItems": 1,
              "maxItems": 100,
              "type": "array",
              "items": {
                "$ref": "#/$defs/__schema18"
              }
            }
          },
          "required": [
            "kind",
            "parts"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema12": {
      "type": "object",
      "properties": {
        "kind": {
          "$ref": "#/$defs/__schema13"
        },
        "source": {
          "$ref": "#/$defs/__schema14"
        },
        "nodeId": {
          "$ref": "#/$defs/__schema15"
        },
        "path": {
          "$ref": "#/$defs/__schema16"
        }
      },
      "required": [
        "kind",
        "source"
      ],
      "additionalProperties": false
    },
    "__schema13": {
      "type": "string",
      "const": "reference"
    },
    "__schema14": {
      "type": "string",
      "enum": [
        "trigger",
        "node"
      ]
    },
    "__schema15": {
      "$ref": "#/$defs/__schema1"
    },
    "__schema16": {
      "default": [],
      "maxItems": 32,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema17"
      }
    },
    "__schema17": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "__schema18": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 10000
        },
        {
          "$ref": "#/$defs/__schema12"
        }
      ]
    },
    "__schema19": {
      "$ref": "#/$defs/__schema11"
    },
    "__schema20": {
      "type": "string",
      "const": "decision"
    },
    "__schema21": {
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema22"
      }
    },
    "__schema22": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema23"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "when": {
          "$ref": "#/$defs/__schema8"
        }
      },
      "required": [
        "id",
        "label",
        "when"
      ],
      "additionalProperties": false
    },
    "__schema23": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{0,63}$"
    },
    "__schema24": {
      "anyOf": [
        {
          "$ref": "#/$defs/__schema11"
        },
        {
          "maxItems": 1000,
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema24"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema24"
          }
        }
      ]
    },
    "__schema25": {
      "default": 3,
      "type": "integer",
      "minimum": 1,
      "maximum": 20
    },
    "__schema26": {
      "default": 5,
      "type": "integer",
      "minimum": 1,
      "maximum": 86400
    },
    "__schema27": {
      "default": 300,
      "type": "integer",
      "minimum": 1,
      "maximum": 604800
    },
    "__schema28": {
      "default": "exponential",
      "type": "string",
      "enum": [
        "fixed",
        "exponential"
      ]
    },
    "__schema29": {
      "default": true,
      "type": "boolean"
    },
    "__schema30": {
      "type": "string",
      "const": "delay"
    },
    "__schema31": {
      "type": "string",
      "enum": [
        "duration",
        "until"
      ]
    },
    "__schema32": {
      "type": "integer",
      "minimum": 1,
      "maximum": 31536000
    },
    "__schema33": {
      "$ref": "#/$defs/__schema11"
    },
    "__schema34": {
      "type": "string"
    },
    "__schema35": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_.:-]{2,127}$"
    },
    "__schema36": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/__schema1"
        },
        "sourceNodeId": {
          "$ref": "#/$defs/__schema1"
        },
        "sourcePort": {
          "$ref": "#/$defs/__schema23"
        },
        "targetNodeId": {
          "$ref": "#/$defs/__schema1"
        },
        "targetPort": {
          "default": "input",
          "$ref": "#/$defs/__schema23"
        },
        "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": {
    "workflowId": {
      "type": "string",
      "pattern": "^workflow_[0-7][0123456789abcdefghjkmnpqrstvwxyz]{25}$"
    },
    "revision": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    }
  },
  "required": [
    "workflowId",
    "revision"
  ],
  "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. Send a stable UUID Idempotency-Key with exactly the same body on retry. Effects and the immutable receipt commit together. Changed payload or stale revision returns 409. Replays reauthorize the current human. Uses the native canonical schema and compiler. Creation additionally requires workflow.create; save uses the canonical draft revision. A linked Explorer draft remains its own editing authority. Does not publish or execute."
}
JSON