---
title: Make Code
slug: code
image: https://make-cxp-documentation.ams3.cdn.digitaloceanspaces.com/apps-center-icons/PREVIEW_DEFAULT.png
docTags: 
createdAt: 2025-08-08T08:29:27.558Z
---

:::hint{type="info"}
Make Code is currently in **Open Beta**. It is available to all customers on [paid plans](https://www.make.com/en/pricing). As a beta feature, both product functionality and pricing may change.
:::

Make Code is a built-in app that allows you to add arbitrary JavaScript or Python code to your scenario.&#x20;

With the Make Code app, you can write code within the module with the help of an IDE that offers familiar features such as common syntax, auto completion, and error highlighting, or you can add code dynamically from previous modules in your scenario. A fully-isolated sandbox environment, as well as access to standard output and error logs, helps you safely test your code, reducing or eliminating the need for third-party tools. Additionally, the app has built-in JavaScript and Python libraries, and with an Enterprise account you can import custom libraries as well. The code created in your Make Code app module is included in downloaded scenario blueprints, making it easier to share and collaborate.

# Key benefits

- Supports JavaScript and Python
- Built-in IDE experience with common syntax, auto completion, and error highlighting
- Fully-isolated sandbox environment to test your code and ensure safe execution
- Access to data outputs and error logs, to help you troubleshoot code executions effectively
- Ability to share code in a scenario blueprint

# Features

| **Features**                                                                                                                         | **Core** | **Pro** | **Teams** | **Enterprise** |
| ------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- | --------- | -------------- |
| Standard JavaScript and Python libraries<br />- JavaScript: moment, moment-timezone, lodash<br />- Python: pendulum, toolz, requests | X        | X       | X         | X              |
| [Ability to import custom libraries](docId\:mkN0za9LLNQPHyF1mXmz8)                                                                   |          |         |           | X              |
| Sandbox environment with:<br />- 1 CPU<br />- 512 MB RAM<br />- 30 second maximum execution time                                     | X        | X       | X         |                |
| Sandbox environment with:<br />- 2 CPUs<br />- 1024 MB RAM<br />- 300 second maximum execution time                                  |          |         |           | X              |

# Credit usage

The Make Code app consumes two credits for every one second of code execution time. You can see the code execution time in the module output.

The billed code execution time does not include backend processing time, so your billed output time will be shorter than the actual time it takes to process.&#x20;

The majority of use cases will execute in less than one second.

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/6DMef3aEdRDn352wPAHdU-20251002-064527.png" size="40" width="886" height="1358" position="flex-start" alt="Output bundle with execution time" showCaption="false"}

Details regarding dynamic credit usage can be found in the [Credits](https://help.make.com/credits#xQfMz) article.

# Make Code module

:::hint{type="info"}
We are currently running **Python version 3.12.11** and **node version 20.19.4**.
:::

## Actions

**Run code**

Design and run a code snippet.

| **Field**                                           | **Description**                                                                                                             |
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **Language**                                        | Select **JavaScript** or **Python**.                                                                                        |
| **Input Format**                                    | Select **Code Editor** or **Mapped Code (useful for AI)**.                                                                  |
| **Code**                                            | Enter the code to be executed, or map dynamic code from previous modules or inputs.                                         |
| **Input**                                           | Provide values from your scenario that can be used within the code. They will be available nested under the `input` object. |
| **Additional Dependencies (Enterprise plans only)** | Add dependencies. Dependencies are installed before executing the code. They are not shared between multiple code modules.  |

:::hint{type="warning"}
Our support team can't provide support in troubleshooting your JavaScript or Python code.
:::



# Add a custom library

If you have an Enterprise plan, you can import custom libraries to use in your Make Code app. In this example, we add axios:

::::WorkflowBlock
:::WorkflowBlockItem
Add `const axios = require('axios');` to your code.
:::

:::WorkflowBlockItem
Under **Advanced settings**, add `axios` to the dependency list.

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/bep27H4RYZwq8QuxbNrff-20251003-140700.png" size="50" width="576" height="439" position="flex-start" alt="Add your custom library as a dependency" showCaption="false"}
:::
::::

# JavaScript examples

::::::ExpandableHeading
**Calculate the number of days between two dates**

In this example, we will use JavaScript to calculate the number of days between two dates. The example contains error handling code to ensure that the entered date is valid and that the start date is not after the end date.&#x20;

:::::WorkflowBlock
:::WorkflowBlockItem
In your scenario, add a **Make Code > Run code** module.
:::

:::WorkflowBlockItem
In the **Language** field, select **JavaScript**.
:::

::::WorkflowBlockItem
In the **Input Format** field, select **Code Editor**.

:::hint{type="info"}
You can also select **Mapped Code** to use code generated in a previous module in your scenario.
:::
::::

:::WorkflowBlockItem
In the **Code** field, enter the following JavaScript code.

The code identifies the name of the variables for input, calculates the result `daysDifference`, and includes examples of both console error and throw error messages if an entered date is invalid or if the start date is after the end date.

- If you include the throw error in your code (lines 18 and 29), the scenario will fail with that error and you can use an error handler.
- If you include the console error in your code (lines 25 and 29), the error will be part of your output bundle.

```javascript
// Retrieve input variables from the scenario
const { start_date, end_date } = input;

// Logging to the Console
console.log("Received a request with the following date: start=" + start_date + ", end=" + end_date);

// Create Date objects from the inputs to ensure they are valid dates.
const start = new Date(start_date);
const end = new Date(end_date);

if (isNaN(start.getTime()) || isNaN(end.getTime())) 
  {
    // Logging error
    console.error("There was an error, one of the dates was not valid");
    
    // Note: if you combine console.error and "throw new Error", the error message will not
    // be displayed, because the Output Bundle will not be generated by the module.
    throw new Error("Invalid date format provided. Please use Date objects or 'YYYY-MM-DD' strings.");
  }

// Ensure the start date is not after the end date.
if (start > end) 
  {
    // Logging error
    console.error("There was an error, the start date is after the end date");
    
    // Note: if you combine console.error and "throw new Error", the error message will not
    // be displayed, because the Output Bundle will not be generated by the module.
    throw new Error("The start date cannot be after the end date.");
  }

// Calculate the difference in milliseconds.
const timeDifference = end.getTime() - start.getTime();

// Convert milliseconds to days and return the result
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24));

// Check if the result is a valid number before returning
if (isNaN(daysDifference)) throw new Error("Calculation resulted in NaN.");
  
return daysDifference;
```
:::

:::WorkflowBlockItem
Variable 1 sets the start date.&#x20;

For the **Name** field, enter `start_date`.

For the **Value** field, map the `now` value for the current date and time.

::Image[]{src="https://api.archbee.com/api/optimize/yAufeXqD1oGWOPBNi5MAm-DdCBKHOrmGsp9MwplQzL6-20250901-095832.png" size="70" width="748" height="586" position="flex-start" alt="Value of variable 1" showCaption="false"}
:::

:::WorkflowBlockItem
Variable 2 sets the end date. Click **+Add variable** to add a second variable to the module.&#x20;

For the **Name** field, enter `end_date`.

For the **Value** field, use the `parseDate` function and add your end date and date format.

::Image[]{src="https://api.archbee.com/api/optimize/yAufeXqD1oGWOPBNi5MAm-vCw9wbFI7flyiu_pgxEU9-20250901-100342.png" size="70" width="797" height="588" position="flex-start" alt="Value of variable 2" showCaption="false"}
:::

:::WorkflowBlockItem
Click **Save&#x20;**&#x74;o save the module settings.
:::

:::WorkflowBlockItem
Click the Save icon in the toolbar to save your scenario.
:::

:::WorkflowBlockItem
Click **Run once** to test.&#x20;
:::
:::::

If the `end_date` is after the `start_date`, the output result is the number of days between the two dates, `daysDifference`.

::Image[]{src="https://api.archbee.com/api/optimize/yAufeXqD1oGWOPBNi5MAm--ixNcdd2s_zV_SoXEN6PF-20250901-105815.png" size="20" width="171" height="98" position="flex-start" alt="output value" showCaption="false"}

If one of the dates is not in the correct format, the throw error will say `Invalid date format provided. Please use Date objects or 'YYYY-MM-DD' strings`.

If the `end_date` is before the `start_date`, the throw error will say `The start date cannot be after the end date`.
::::::

:::ExpandableHeading
**Real-time API response parser**

```javascript
const res = await fetch("https://randomuser.me/api/");
const data = await res.json();
return data;
```

Although this is possible, we recommend using the [HTTP module](https://apps.make.com/http) for API calls to ensure your credentials are properly protected and not exposed to other users in your organization through scenario logs. Sanitization is left to your discretion when using the Make Code app.
:::

:::ExpandableHeading
**Input scheme safely**

`zod` needs to be installed.

```javascript
const { z } = require("zod");
const schema = z.object({
  email: z.string().email()
});
const input = { // or you can use Context to input data from scenario
    email: "email@email.com"
}
const parsed = schema.safeParse(input);
if (!parsed.success) {
  throw new Error("Invalid email format");
}
return { valid: true };
```
:::

:::ExpandableHeading
**One-time password (OTP) generator**

`otplib` needs to be installed.

```javascript
const { authenticator } = require("otplib");
const secret = "KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD";
const token = authenticator.generate(secret);
return { otp: token };
```
:::

:::ExpandableHeading
**Business hours calculator**





`luxon` needs to be installed.

```javascript
const { DateTime } = require("luxon");
const input = { // or you can use Context to input data from scenario
  "timestamp": "2025-07-07T15:00:00Z",
  "timezone": "America/New_York"
}
const dt = DateTime.fromISO(input.timestamp, { zone: input.timezone });
const hour = dt.hour;
const isOpen = hour >= 9 && hour < 17;
return {
  localTime: dt.toFormat("HH:mm"),
  isOpen
};
```
:::

# Python example

:::ExpandableHeading
**Fetch JSON data from a URL with error handling**

There is no need to install any additional libraries for this example.

```python
import requests
import sys

url = input.get('url')  # Assuming input is a dict with a 'url' key
print(url)

try:
    response = requests.get(url)
    response.raise_for_status()  # Raise an error for HTTP errors
    data = response.json()
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}", file=sys.stderr)
    data = None
except ValueError as e:
    print(f"Failed to parse JSON: {e}", file=sys.stderr)
    data = None

return data
```

Add the URL as an input variable:

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/3MeNOZP1fir7BFIUeUYF6-20251007-113623.png" size="50" width="958" height="752" position="flex-start" alt="Add the URL as an input variable" showCaption="false"}
:::

