Quicklinks

Automation Code Steps

Code steps provide powerful, secure, and flexible scripting to Kizen Automations using Python. Code Steps natively integrate with automation variables and field values from your custom object entities. All code runs in an isolated container.

Available Runtimes

  • Python 3.12
  • Python 3.13

 
In addition to packages included in the Python Standard Library, the following packages come pre-installed:

  • bcrypt
  • lxml
  • msgpack
  • numpy
  • pytz
  • requests

 

Limits

  • 1 GB RAM
  • 30 sec execution time

 

Using Inputs and Generating Outputs

Your python code will access input data in an object named inputs and write to an object named outputs. The names of the attributes are set when you select inputs and outputs in your Kizen Automation.

This example assumes an input called “name” and an output called “greeting”

outputs.greeting = "hello, " + inputs.name + "!"

Screenshot of Automation Code Step Configuration Dialog

Logging

You may write logs using the provided outputs.log() function.

Example:

from datetime import datetime
outputs.log(f"Started at: {datetime.now()}")

To view these logs:

1. Open the Automation History, for example by navigating to entity record you’ve run this automation on, and clicking the “Automation Name” for an execution in the list

Screenshot of Automation History on an Entity Record

2. Then — in the Automation History view — click the Execution Status in Code Step Action (the word “Completed” in the screenshot):

Screenshot of Code Step in Automation History View

3. You will see your Execution details, including any logs you’ve written:

Screenshot of Code Step Execution Details

Validating Inputs and Raising Errors

You can raise an Exception to immediately stop execution of your Python code due to invalid data or other unexpected cases.

outputs.log("Checking for Aristotle...")

if inputs.first_name == 'Aristotle':
    raise ValueError("Unexpected Mathematician")
else:
    outputs.greeting = f"Hello, {inputs.first_name}!"

This error will be visible in the Execution details:

Screenshot of Error details in Code Step Execution Details

A successful execution will show the inputs, outputs, and logs (more detail on the encoding of inputs and outputs later in this document):

Screenshot of Code Step Execution Details including inputs, outputs, and logs

Making HTTP Requests

The ability to send HTTP requests enables powerful, flexible integrations.

import requests

resp = requests.post(
  "https://httpbin.org/anything",
  json={"greeting": "Hello, world!"}
)
outputs.log(f"Got {len(resp.content)} bytes")

Integration Secrets

You may also configure your Code Step with access to use Integration Secrets.

Screenshot of

import requests

my_secret = secrets["magicword"]

resp = requests.get(
    "https://httpbin.org/anything",
    headers={"Authorization": f"Bearer {my_secret}"}
)
outputs.log(resp.text)

HTTP Request Logs

In addition to messages you log directly in your code, HTTP requests are logged automatically.

In your HTTP request logs you’ll find:

  • Total number of HTTP requests sent
  • Detailed logs of the first 100 requests sent:
    • HTTP Method
    • URL
    • Request and Response Headers
    • Request Body (truncated to the first 1 kB)
  • Number of requests sent without capturing detailed logs (due to exceeding the 100-request threshold)

 
This info will appear in the Execution Details:

Screenshot of Code Step Execution History showing HTTP Request Logging

Kizen Data Types and Data Encoding

When you view the Automation History for a Code Step, or use the Immediate/sync API for CodeRunner you will see your kizen values encoded as JSON using the following scheme:

Data TypeType CodeExample
Booleanb
{"t": "b", "v": "false"}
Dated
{"t": "d", "v": "2024-12-25"}
DateTimedt
{"t": "dt", "v": "2024-03-14T01:59:26.535897+00:00"}
Phone Numberp
{"t": "p", "v": "+15125551212"}
Strings
{"t": "s", "v": "Hello, World!"}
UUIDu
{"t": "u", "v": "c6f9fe22-9d2c-4dca-9380-ab9733c85303"}
Entity Recorde<uuid>The UUID in the type code indicates which Custom Object the entity is part of.
{
"t": "e<06e86916-cc8e-4622-af2f-8e9c08e9225b>",
"v": "643eb36c-744c-4928-8e21-077acb65eaef"
}
Field Optiono<uuid,uuid>The first UUID in the type code is the Custom Object id, the second UUID is the Field id.
{
"t": "o<f87c4d49-9de2-4701-a7d1-73eda1783e25,28ca3e62-592e-4036-a7a9-0e2fd500d8f5>",
"v": "24fb871d-f1df-42a9-8dac-1adb24bb03f6"
}
Array (typed)a[...]
{
"t": "a[s]",
"v": ["Einstein", "Newton", "Pythagoras"]
}
List (untyped)lNote: Values are individually encoded, may be an empty list, and may be null.
{
"t": "l",
"v": [
{"t": "b", "v": "false"},
{"t": "d", "v": "2024-12-25"}
]
}