input and must return one or more Firmhouse actions for the Journey to execute.
Script Execution is currently a private beta feature. During the beta, Firmhouse staff needs to enable it for your project.
What it is
Script Execution is useful when you need custom Journey logic that is not covered by the standard workflow presets. Instead of directly changing a subscription from the script, your script decides which supported action Firmhouse should execute next. The script:- must contain valid JavaScript
- receives the subscription context as
input - must
returnan array of action objects - cannot perform direct side effects in Firmhouse by itself
Add a Script Execution workflow
- Ask the Firmhouse support team to enable the Script Execution beta for your project.
- Open your project in the Firmhouse portal.
- In the sidebar, go to Workflows.
- Click Create new workflow.
- Choose Script Execution.
- Enter a name for the workflow and optionally add a description.
- Paste your JavaScript into the script editor.
- Optionally, add Input Parameters (see below).
- Click Save workflow.
Input Parameters
Input Parameters let you define key/value pairs that become available in your script. This lets you write a single reusable script and configure it differently per workflow — without editing JavaScript. Your script receives the parameters in two forms:input.params— the raw array of parameter objects exactly as configured, e.g.[{"key": "order_1", "type": "product", "value": "gid://..."}, ...]. Use this when you need access to the full metadata (type, individual entries).input.params_normalized— a convenience hash that groups values by key, e.g.{"order_1": "gid://...", "order_2": ["gid://...", "gid://..."]}. Duplicate keys are automatically collected into arrays. Use this for simple key-based lookups.
Parameter types
Each parameter has a Type selector:- Text (default) — Enter any plain text value. The value is always passed to your script as a string. If you need array-like behaviour, use a comma-separated or pipe-separated value and split it in your script (e.g.
"a,b,c".split(",")). - Product — Select a product from your catalog using a search autocomplete field. This makes it easy to deterministically reference a specific product in your input parameters without needing to look up its ID. The selected product’s Global ID is stored and passed to your script as a string (e.g.
"gid://firmhouse/Product/123").
order_2 and type Product will appear as two separate entries in input.params. In input.params_normalized, they are grouped into an array: input.params_normalized.order_2 → ["gid://firmhouse/Product/101", "gid://firmhouse/Product/102"].
The script protocol
Your script must return an array. Each item in the array must be an object with:functionarguments
Rules
- The script must use valid JavaScript syntax.
- The script must
return [...], not{ actions: [...] }. - The returned value must be an array.
- Each action must be an object.
functionmust be one of the supported function names listed below.argumentsmust be an object.- Required arguments must be present.
- Extra arguments are rejected.
- Argument types must match the expected types.
Copy-paste examples
No-op / smoke test
Use this script to verify that the workflow executes successfully without changing the subscription.Product swap example
Use this script as a starting point for a workflow that supports multiple source-to-target product mappings and returns one swap action for each matching current product.Promotion by confirmed orders count
Use this script when you want to apply different promotions after specific order milestones. In this example, one promotion is applied after 3 confirmed orders and another after 6 confirmed orders.Product sequence with revolving cycle
Some subscription businesses ship different products depending on where the subscriber is in their journey. For example, a health supplements brand might send a starter kit on the first order, then alternate between two different refill packs from order 2 onward. After the first checkout order and possible follow-up orders, you can configure a revolving cycle that spans multiple orders. This script uses Input Parameters to configure which products belong to each order in the sequence. You do not need to edit the JavaScript — just set the parameters in the workflow form.Real-world example
Imagine a supplements brand that works like this:- The customer checks out with a Starter Kit (order 1).
- On order 2, the subscription switches to two refill products: Refill Pack A and Refill Pack B.
- On order 3, the subscription has only Refill Pack A.
- From order 4 onward, orders 2 and 3 keep repeating: the customer alternates between receiving both refill packs and just one.
| Key | Type | Value |
|---|---|---|
order_1 | Product | Starter Kit |
order_2 | Product | Refill Pack A |
order_2 | Product | Refill Pack B |
order_3 | Product | Refill Pack A |
restart_from_order_2 | Text | true |
- Order 1 → Starter Kit (checkout order — already on subscription at signup)
- Order 2 → Refill Pack A + Refill Pack B (removes Starter Kit, adds both refills)
- Order 3 → Refill Pack A (removes Refill Pack B, keeps Refill Pack A)
- Order 4 → Refill Pack A + Refill Pack B (cycles back to order 2)
- Order 5 → Refill Pack A (cycles back to order 3)
- …and so on
How the Input Parameters work
Each key follows theorder_X format, where X is the order number. Set the type to Product and search for the product you want.
To add multiple products to the same order, add multiple rows with the same key (e.g. two rows both named order_2, each with a different product). The script collects all products for that order automatically.
order_1 represents the checkout order — the products the customer receives at signup. These are already on the subscription, so the script does not add them. It uses order_1 to know which products to remove when moving to order_2.
Add a key named restart_from_order_X (e.g. restart_from_order_2) with any value (e.g. true) to set where the revolving cycle begins. Once all configured orders have been fulfilled, the sequence loops back to this order number and repeats indefinitely.
The script
Paste this script into the Script Execution workflow. It reads the Input Parameters and handles add/remove automatically.Supported functions
no_action
Use this when the Journey should continue without making any subscription change right now.
Required arguments:
reason(string)
swap_product_by_id
Use this to replace one product on the subscription with another product.
Required arguments:
current_product_id(string)new_product_id(string)reason(string)
firmhouse namespace in these Global IDs, for example gid://firmhouse/Product/123. Do not use gid://gomonthly/..., because those IDs will not work in Script Execution workflows.
Example:
update_next_billing_date
Use this to move the subscription’s next billing date.
Required arguments:
next_billing_date(string, ISO date formatYYYY-MM-DD)reason(string)
apply_promotion
Use this to apply a promotion to the subscription.
Required arguments:
promotion_id(string)reason(string)
add_product_to_subscription
Use this to add a product to the subscription.
Required arguments:
product_id(string) — Firmhouse product Global IDreason(string)
quantity(string) — defaults to"1"if not provided
remove_product_from_subscription
Use this to remove a product from the subscription.
Required arguments:
product_id(string) — Firmhouse product Global IDreason(string)
stop_journey
Use this when the Journey has reached its end and should not continue for this subscription.
Required arguments:
stop_journey(boolean)reason(string)
What input contains
Firmhouse passes the current subscription context into your script as input. At the moment this payload follows a fixed structure.
The current input payload contains:
signed_up_atconfirmed_orders_countconfirmed_or_fulfilled_orderscurrent_productscurrent_promotionsactive_planparams— the raw array of Input Parameter objects you configured on the workflow (empty array[]when none are set). Each entry haskey,type, andvalue.params_normalized— a convenience hash that groupsparamsby key. Duplicate keys become arrays. Empty object{}when no parameters are set.
Field details
signed_up_atThe subscription sign-up timestamp.confirmed_orders_countThe number of confirmed or fulfilled orders on the subscription.confirmed_or_fulfilled_ordersThe confirmed or fulfilled orders, including their order lines.current_productsThe currently active products on the subscription, including instalment-related fields:product_id,instalment_original_product_id, andinstalment_current_number.current_promotionsThe promotions currently applied to the subscription.active_planSelected plan details for the subscription, including bothsubscribed_planattributes and fullplanattributes.
input object in your script and use the fields you need in your logic.
input.params contains the raw array of parameter objects you defined in the Input Parameters section of the workflow form. input.params_normalized provides the same data grouped by key for convenient lookups. See Input Parameters for details on how to configure them.
Troubleshooting
If the script does not save or does not run correctly, check the following:- the script contains valid JavaScript
- the script returns an array
- every action includes
functionandarguments - all required arguments are present
- there are no extra unsupported arguments
- the argument types match the required types
- your project ID
- the name of the workflow
- the script you saved
- the action you expected the script to return