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 + "!"
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
2. Then — in the Automation History view — click the Execution Status in Code Step Action (the word “Completed” in the screenshot):
3. You will see your Execution details, including any logs you’ve written:
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:
A successful execution will show the inputs, outputs, and logs (more detail on the encoding of inputs and outputs later in this document):
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.
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:
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 Type | Type Code | Example |
---|---|---|
Boolean | b |
|
Date | d |
|
DateTime | dt |
|
Phone Number | p |
|
String | s |
|
UUID | u |
|
Entity Record | e<uuid> | The UUID in the type code indicates which Custom Object the entity is part of.
|
Field Option | o<uuid,uuid> | The first UUID in the type code is the Custom Object id, the second UUID is the Field id.
|
Array (typed) | a[...] |
|
List (untyped) | l | Note: Values are individually encoded, may be an empty list, and may be null .
|