Skip to content

Generate outbound template

You can generate templates for use in Camunda SaaS or Camunda Modeler from you outbound connectors.

Python Camunda SDK includes a generate_template command-line tool to help you.

$ generate_template --help

Usage: generate_template [OPTIONS] CONNECTOR FILENAME

    Generates a template from a CONNECTOR and saves it to FILENAME.

    CONNECTOR must be a a full class name including the module name, e.g.
    mymodule.submodule.MyConnector.

Options:
    --help  Show this message and exit.

For example, if LogConnector is a part of the example module, we can run

$ generate_template example.LogConnector example/log.json
Generated template for example.LogConnector

Tip

You can skip to Create process to learn how to load the template to Modeler.

Template conversion

LogConnector class have been converted to a template:

  • name of the template was picked up from ConnectorConfig.name
  • zeebe:taskDefinition:type was set to ConnectorConfig.type (not visible in Modeler).
  • message field of the LogConnector was converted into a zeebe:input property.
  • A zeebe:taskHeader with key 'resultVariable' was added to allow users define the name of the variable where the output of the LogConnector.run method will be stored.

Template

{
  "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema@0.9.0/resources/schema.json",
  "name": "LogConnector",
  "id": "1d696704-d29c-4a80-94f1-89b8fd3735b7",
  "appliesTo": [
    "bpmn:ServiceTask"
  ],
  "properties": [
    {
      "binding": {
        "type": "zeebe:input",
        "name": "message"
      },
      "label": "Message to log",
      "type": "String",
      "group": "input",
      "feel": "optional"
    },
    {
      "binding": {
        "type": "zeebe:taskHeader",
        "key": "resultVariable"
      },
      "label": "Result variable",
      "type": "String",
      "group": "output"
    },
    {
      "binding": {
        "type": "zeebe:taskDefinition:type"
      },
      "type": "Hidden",
      "value": "log"
    }
  ],
  "groups": [
    {
      "id": "input",
      "label": "Input"
    },
    {
      "id": "output",
      "label": "Output"
    }
  ]
}
from pydantic import BaseModel, Field
from loguru import logger

from python_camunda_sdk import OutboundConnector


class StatusModel(BaseModel):
    status: str


class LogConnector(OutboundConnector):
    message: str = Field(description="Message to log")

    async def run(self) -> StatusModel:
        logger.info(f"LogConnector: {self.message}")

        return StatusModel(status="ok")

    class ConnectorConfig:
        name = "LogConnector"
        type = "log"