> ## Documentation Index
> Fetch the complete documentation index at: https://domoinc-openapi-sync-dataflows.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Engine

export const InlineImage = ({src, alt = '', height = '1.6em'}) => {
  return <img noZoom src={src} alt={alt} style={{
    display: 'inline',
    verticalAlign: 'start',
    height: height,
    margin: '0'
  }} />;
};

### Intro

Code Engine is a Domo-native runtime environment that can execute JavaScript or Python code. In Code Engine, you can write, test, and distribute functions usable by Workflows and in other Domo Apps.

Domo provides a [library](#code_engine_library) of general packages and their related functions for common integrations and services that anyone with access to Code Engine can use. You can also create functions with custom code to perform automated services in your instance.

***

### Required Grants

The following grants provide user-based rights to Code Engine in your Domo environment. Those with grants to Code Engine must also have permission to one or more specific packages within Code Engine to interact with the packages. Learn about [permissions](#permissions) below.

* **Manage Code Engine Packages —** Allows you to perform any action on any Code Engine package in the instance. This grant should be given to admins or anyone who helps manage Code Engine.
* **Create Code Engine Packages —** Allows you to create a new Code Engine package. This grant should be given to anyone who needs to create and add new function packages to the Code Engine repository in your instance.

  <Note>
    **Note:** Contact your Domo account team to enable either of these grants for your instance. For information about the available permissions for non-instance admin users, see the [Permissions](#permissions) section of this article.
  </Note>

### Access Code Engine

To access Code Engine from the navigation header, select **More** > **Workflows** to display the Workflows landing page.

In the left navigation, select <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000002pStx.jpg" /> **Code Engine**.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WO9C.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=6f810683ebfb68acafdb009946722600" style={{width: 548, height: 449}} width="1264" height="1034" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WO9C.jpg" />
</Frame>

The Code Engine home page displays.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPBh.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=32b3aef8b22dad44dcfc9b1dced7bc89" style={{width: 899, height: 309}} width="3580" height="1230" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPBh.jpg" />
</Frame>

### Home Page

The main feature of the Code Engine home page is a [list](#code_engine_repository_list) of all the Code Engine packages available to you based on your [permissions](#permissions). From here, you can also create new packages and access the code editor to edit existing packages.

From the left navigation, you can access complementary features: [Workflows](/s/article/000005108), [Forms](/s/article/000005171), and [Task Center](/s/article/000005172). If you don't see the options for these features in the left navigation, they are not enabled for your instance. Contact your Domo account team about enablement.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPTR.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=2bad7d6e9f1dd429cfea6a95a31ee392" style={{width: 899, height: 309}} width="3580" height="1230" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPTR.jpg" />
</Frame>

# Code Engine Repository List

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/fpoofI6keqS4BAx0/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf0B.jpg?fit=max&auto=format&n=fpoofI6keqS4BAx0&q=85&s=60c87a75a946714486bc61ee8b9b3f04" width="3234" height="158" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf0B.jpg" />
</Frame>

The Repository List is the main feature of the Code Engine home page. Each row in the list represents an individual package. The columns in the list are described below:

* **Package Name/Description —** Displays the title of the package and a brief description.
* **Owned By —** Displays the package creator/owner's name and avatar.
* **Runtime —** Displays the runtime (or programmatic language) the package is using.
* **Last Saved —** Provides the date when the package was last updated.
* **Created —** Provides the date when the package was created.

Select anywhere in a row to open that package in the [code editor](#code_editor).

### Create a Custom Package

You can create a custom function package from the Code Engine [home page](#home_page) by following the steps below.

1. Select **+ New Package**. If the option is disabled, make sure you have the [required grants](#required_grants). If you do have the grants and still can't create a new package, reach out to your Domo account team or contact [Domo Support](https://domo-support.domo.com/s/) <InlineImage src="/images/kb/ka0Vq00000001FR-00N5w00000Ri7BU-0EMVq0000000XDh.jpg" />.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPmn.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=d18bb53f2508d71f8ae4e0824153ad07" style={{width: 899, height: 309}} width="3580" height="1230" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPmn.jpg" />
   </Frame>

   The **Create New Package** modal displays.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPtF.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=6ae4580f04e8f1f6da21209945e3ecaf" style={{width: 400, height: 286}} width="1348" height="964" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WPtF.jpg" />
   </Frame>

2. (Required) Fill in the **Package Name** and **Package Description** fields.

3. (Required) Choose an option from the **Select a Language** dropdown. The options are JavaScript and Python.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQ7l.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=c05f4882ebae63c33670563653a57202" style={{width: 403, height: 290}} width="1342" height="966" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQ7l.jpg" />
   </Frame>

4. (Optional) You can upload a thumbnail for increased package visibility.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQJ3.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=e7e33f1643422f5ae044acef65c1d4e1" style={{width: 401, height: 286}} width="1346" height="960" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQJ3.jpg" />
   </Frame>

5. Select **Create New Package** to display the package in the [code editor](#code_editor) or **Cancel** to return to the home page.

### Create a New Package Version

When you need to make changes to a package, such as updating a function or adding a new function, you must create a new version of the package to make the updates. When you open a package in Code Engine or access the package modal in Workflows, the latest version of the package is the default, but you can choose an earlier version if needed.

Follow these steps to create a new package version in the [code editor](#code_editor).

1. Open the package in the code editor.

2. Select
   <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WKf5.jpg" /> **Expand** > <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000JtDh.jpg" /> **Create New Version** to display the new version modal.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQsX.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=6dc83ec42e3222dfe7b61cca3651509e" style={{width: 902, height: 265}} width="3580" height="1052" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQsX.jpg" />
   </Frame>

   <Frame>
     <img alt="Screenshot 2023-05-04 at 5.12.16 PM.png" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/fpoofI6keqS4BAx0/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf1x.jpg?fit=max&auto=format&n=fpoofI6keqS4BAx0&q=85&s=eb3daaf8fffa7a237e60b38856f3e31c" style={{width: 383, height: 396}} width="930" height="960" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf1x.jpg" />
   </Frame>

3. In the **Version to Copy From** dropdown, select a target version of the package to copy all of its contents into the new version. This includes syntax, variables, and any metadata.

<Frame>
  <img alt="Screenshot 2023-05-04 at 5.13.17 PM.png" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/fpoofI6keqS4BAx0/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf22.jpg?fit=max&auto=format&n=fpoofI6keqS4BAx0&q=85&s=3c3d5e8bc373aea0190e3320246061a6" style={{width: 367, height: 395}} width="874" height="940" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uf22.jpg" />
</Frame>

4. In the **Version** field, enter the version number you want, according to Semantic Versioning (see the official [spec](https://semver.org/) <InlineImage src="/images/kb/ka0Vq00000001FR-00N5w00000Ri7BU-0EMVq0000000XDh.jpg" /> ). The field contains a default value, but you can change it.

   <Frame>
     <img alt="Screenshot 2023-05-09 at 2.56.29 PM.png" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/fpoofI6keqS4BAx0/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uhD8.jpg?fit=max&auto=format&n=fpoofI6keqS4BAx0&q=85&s=1067dc1eec2bf9b16c750b42dc67694d" style={{width: 370, height: 408}} width="846" height="934" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006uhD8.jpg" />
   </Frame>

5. (Optional) Enter any details in the **Version Description** field.

6. Select **Create New Version** to save your changes and create a new version of the package.

   The new version becomes the package's default version, but if you want to access an earlier version, you can open the package in the code editor and choose another version from the [version list](#version_list).

### Code Editor

The code editor serves as an integrated development environment (IDE) for writing code, configuring function inputs/outputs, and testing the functions in real time. A package can contain multiple functions. You must code and configure each function in the code editor.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WSXl.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=4a1f6db9b00da7fe11b73cfe724f892f" style={{width: 898, height: 405}} width="3574" height="1612" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WSXl.jpg" />
</Frame>

# Package Information/Action Bar

At the top of the code editor is the package information/action bar. The list below describes the elements in this area and their various functions.

<InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WSeD.jpg" />

* **Back arrow —** Redirects to the Code Engine [home page](#home_page).
* **Package thumbnail —** The image associated with the package.
* **Package Title/Description —** The title and description given to the package when it was created.
* **Last Saved —** The date the package version was last saved.
* **Runtime/Language —** The programming language used to write the script.
* **Owner thumbnail —** The avatar for the package owner.
* **Share button —** Opens the [permissions](#permissions) modal.
* **Dark Mode toggle —** Enables/disables dark mode for the code editor.
* **Version list —** Allows you to select which version of the package you want to view/edit.
* **Save —** Allows you to save your changes to the package if code syntax and variables are valid.
* **Save options —** Provides the following options for the package:
  * **Create New Version —** Displays the **Create New Version** modal. See [Create New Version](#create_new_version) for more information.
  * **Delete Current Package —** Permanently deletes the package.
  * **Delete Current Version —** Permanently deletes the version.
  * **Save and Deploy —** If code syntax and variables are valid, your changes are saved and the new version of the package deploys. This disables editing for the deployed version and makes it available for use by other Domo features, such as Workflows.

    <Frame>
      <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WSnt.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=d40608c126022c3e6e123da1c41a43ab" style={{width: 298, height: 280}} width="518" height="486" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WSnt.jpg" />
    </Frame>

# Permissions

Within Code Engine, you can use the permissions modal to give other users or groups permission to perform actions for a specific package. All permissions are granted at the package level.

This list describes the various permissions or levels of access:

* **Admin —** Allows a user to perform any action on the package. This permission is different from the [Manage Code Engine Packages grant](#required_grants), which gives access to all packages in the instance.
* **Delete —** Allows a user to delete a package or a version of a package.
* **Read —** Allows a user view-only access to package metatdata and its versions.
* **Write —** Allows a user to edit a package.
* **Share —** Allows a user to grant another user equal or lesser access to a package.
* **Execute —** Allows a user to run a function in a package.
* **Read Content** **—** Allows a user view-only access to the code content of a package and its versions.
* **Update Content —** Allows a user to edit the code content and metadata of a package and its versions.

To grant permissions, follow the steps below.

1. In the package information/action bar, select
   <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WLha.jpg" /> **Share** to display the permissions modal.

   <Frame>
     <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WOUC.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=9c3337d3ef0ac88688cfec68729470a5" style={{width: 592, height: 107}} width="1870" height="338" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WOUC.jpg" />
   </Frame>

   The permissions modal contains a search bar, a list of People With Access to the package, and a list of People Without Access to the package. By default, the owner of the package always has Admin permission to the package.
2. In the search bar, enter the name of a person or group for which you want to edit permissions. If the user or group is found in the instance, the name displays at the top of the list of People Without Access. The permissions menu displays next to the user or group name; the default permission is No Access.
3. Select the permission you want to grant the user or group.
4. Select **Save** to save your changes.

# Side Navigation

The code editor's side navigation allows you to view and configure metadata and variables related to either the package itself or the code in the editor.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WTSD.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=9a000dabdbf39ed7c09e8a7d1595a4a4" style={{width: 897, height: 312}} width="3184" height="1108" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WTSD.jpg" />
</Frame>

There are two sections in the side navigation. Selecting a section expands the side panel to display options for that section.

* <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EM5w000006ugY9.jpg" />
  [Function Configuration](#function_configuration)
* <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000FzZR.jpg" />
  [Package Information](#package_information)

#### Function Configuration

In the **Function Configuration** section, you can configure the description, inputs, and optional output for a function in a package. A package can contain multiple functions.

You must save the input variable names and types to be able to save the function.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQ2w.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=566d82d0cc7f475fda334cd8cd294b51" style={{width: 646, height: 585}} width="1782" height="1614" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WQ2w.jpg" />
</Frame>

The elements in the **Function Configuration** section are described below.

<table border="1" cellpadding="1" cellspacing="1" data-aura-rendered-by="33:205;a"><thead><tr><th colspan="1" rowspan="1"><p> Element </p></th><th colspan="1" rowspan="1"><p> Description </p></th></tr></thead><tbody><tr><td colspan="1" rowspan="1"><p><b> Select a function </b> dropdown </p></td><td colspan="1" rowspan="1"><p> This list populates with all of the functions that were parsed and found in the code editor. All other fields in the panel are based on the selected function. </p><p> If a function you wrote does not appear in the list, select <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000Fzcf.jpg" /><b> Rescan </b><b> Functions </b> to allow Code Engine to parse and find the new function. </p></td></tr><tr><td colspan="1" rowspan="1"><p> Function description field </p></td><td colspan="1" rowspan="1"><p> A brief summary of the function's purpose. </p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Inputs </b> tab </p></td><td colspan="1" rowspan="1"><p> In this tab, you can add input parameters to the function by selecting <b> Add Input </b>. For each input, you must specify a data type and enter a name for it. If there is no data type specified, the field displays with a red border and you cannot save the function configuration. </p><p> After selecting a data type and entering a name, select <InlineImage alt="save param.jpg" src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GE73.jpg" style={{width: 30, height: 29}} /><b> Save </b> or <InlineImage alt="cancel param.jpg" src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GCOc.jpg" style={{width: 30, height: 29}} /><b> Cancel </b>. You can also do this in the code editor. To learn more, see <a href="#input_variables" target="_self"> Input Variables and Return Types </a> below. </p><p><img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WND8.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=de4cd92e57d778195da4cff8fc07ddff" style={{width: 274, height: 393}} width="632" height="906" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WND8.jpg" /></p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Output </b> tab </p></td><td colspan="1" rowspan="1"><p> In this tab, you can add an output parameter to the function. Select the variable type and enter a name for it. Then select <InlineImage alt="save param.jpg" src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GE73.jpg" style={{width: 30, height: 29}} /><b> Save </b> or <InlineImage alt="cancel param.jpg" src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GCOc.jpg" style={{width: 30, height: 29}} /><b> Cancel </b>. </p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Input Parameters </b></p></td><td colspan="1" rowspan="1"><p> A list of all input parameters declared in the function. <a id="output_parameters" target="_blank" /></p><p><img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUmT.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=81fb4ddf3aab47c1f41e518c3f309768" style={{width: 350, height: 306}} width="618" height="540" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUmT.jpg" /></p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Output Parameter </b></p></td><td colspan="1" rowspan="1"><p> The output parameter defined in the function. You can only have one output parameter. An output parameter is not required to build a successful function, but it is best practice to add one so that you can get a return value and know if your function was successful. <a id="input_variables" target="_blank" /></p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Is List? </b></p></td><td colspan="1" rowspan="1"><p> In the <b> Edit parameter </b> modal, check this box if the output variable is an array of its specified type. <br /><br /><img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUxl.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=d15cc23acb74a880c64f2987735b62c1" style={{width: 377, height: 217}} width="1160" height="668" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUxl.jpg" /></p></td></tr><tr><td colspan="1" rowspan="1"><p><b> Rescan Functions </b> (<InlineImage alt="" src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WVLx.jpg" style={{width: 23, height: 24}} /> ) </p></td><td colspan="1" rowspan="1"> Rescans the package to parse functions and variables. </td></tr></tbody></table>

##### Input Variables and Return Type

When configuring the Input Parameters, you must select a data type for each parameter or Input Variable. The available data types include:

* Account (This data type has slightly different handling. See
  [Account Data Type](#account_data_type) below.
* Boolean
* DataSet
* Date
* Datetime
* Decimal
* Duration
* Group
* Number
* Object
* Person
* Text
* Time

These options are generally self-explanatory. For example, if you need to store text-based strings, use the **Text** type. For more configuration options, see [Advanced Editing for Parameters](#advanced_editing).

<Note>
  **Note:** Defining a data type for each Input Variable is critical for how the function is consumed outside of Code Engine, so you cannot save the function without defining them.

  For example, in a workflow, selecting a function from a Code Engine package can power the actions of the workflow. In Workflows, when you select a function, the workflow's configuration panel displays the inputs and outputs from the Code Engine function so that you can map the Variables of the workflow to the inputs of the function and the output of the function to a Variable in the workflow (if there are outputs of the function configured).

  While [output parameters](#output_parameters) are not required, if you do add one or more output parameters, you must define a Return Type for each output in Code Engine so they can be mapped in the workflow where you are using the function.
</Note>

##### Advanced Editing for Parameters

To access the advanced editing options for parameters, select **More** (vertical three-dot menu) for that parameter in the **Input Parameters** list, then select **Advanced Edit**. If you have defined an output parameter, you can access the advanced editing options by selecting **More** (vertical three-dot menu) > **Advanced Edit** in the **Output** tab.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WOcE.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=f843c383e5c91b6aad5a829cff502d57" style={{width: 350, height: 200}} width="632" height="362" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WOcE.jpg" />
</Frame>

The **Edit Parameter** modal displays.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUxl.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=d15cc23acb74a880c64f2987735b62c1" style={{width: 450, height: 259}} width="1160" height="668" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WUxl.jpg" />
</Frame>

In the modal, you can change the parameter name and data type, choose to make the parameter a list of the specified data type, and/or make the variable nullable. You can also add or delete a default value.

###### Account Data Type

If you choose an Account data type, you must choose a data provider. In this example, the system is pulling from a Google spreadsheet, so Google Sheets is the data provider.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRiA.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=b9d8f9b16884d98e7f5ad1f0fc48706e" style={{width: 448, height: 439}} width="1154" height="1132" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRiA.jpg" />
</Frame>

After saving your data provider, go to the function where that parameter appears and select **Start function**.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WWBZ.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=6a9260a4445430068624fdfbe08314a9" style={{width: 850, height: 406}} width="1902" height="908" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WWBZ.jpg" />
</Frame>

In the **Start Function** modal, enter a value for each required field.

In this example, choose a Google account and add a sheet ID.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WWOT.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=080f7f24a00e4e098223a753e83e0ecb" style={{width: 599, height: 286}} width="1328" height="634" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WWOT.jpg" />
</Frame>

Select **Start Function** to test the values.

If the function is successful, the response displays in the **Response** panel.

###### List Type

Choosing **List** as the data type defines the Input Variable or the Return Type as containing a list. It does not define what is in the list. If you want to define a list of another type, you can select that type and then check the box labeled **Is List?** box. Your parameter will then be defined as a list of variables of that type.

###### Object Type

The **Object** type is useful for storing complex types. An object can be Open or Defined:

* **Open —** You can store any type of data in an Open Object, but what is stored in the object is not explicitly defined. This is useful for operating on APIs that return complex data.
* **Defined Object —** For a Defined Object, you define child properties of the object by selecting **Add Child Property** in the modal.

  <Frame>
    <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRn0.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=5d6bc6189f0d08e05c5f788249854734" style={{width: 597, height: 289}} width="1646" height="796" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRn0.jpg" />
  </Frame>

  When you add a child property, a row opens for each child property on the Object. Here, you can define the parameter name and data type for each child property of the Object.

  For example, you may have an Address Object that has child properties for the street, city, state (all TEXT type), and postal code (NUMBER type).

  <Frame>
    <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WX9F.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=dacbd417f366d49dc7e3d124b42fd95c" style={{width: 600, height: 409}} width="1646" height="1122" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WX9F.jpg" />
  </Frame>

#### Package Information

The **Package Information** section contains the following metatdata:

* **Name —** The function name.
* **Created —** The date the package version was created.
* **Last Deployed —** The date the package version was deployed.
* **Language —** The programming language the script is written in.
* **Owner —** The name and avatar of the package owner.
* **Description —** A brief description of the package.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WXlx.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=f0a9090cd360e3e68c742bf96e15f3d3" style={{width: 301, height: 445}} width="746" height="1106" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WXlx.jpg" />
</Frame>

### Test a Function

After you enter the code and parameters for a function, you can test the function before deployment.

# Prerequisites

Check for issues with the function syntax and variables. For example, if a parameter displays with a red border, make sure it has a defined type and no outstanding configuration issues.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WYTV.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=9639d6c96253527b80b5ce5ba2aff58d" style={{width: 300, height: 91}} width="652" height="198" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WYTV.jpg" />
</Frame>

In the code editor, select <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WWuk.jpg" /> **Start Function** to open the start modal.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRQR.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=0370bf740e7160be1fef490d1a824a56" style={{width: 499, height: 173}} width="1594" height="552" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WRQR.jpg" />
</Frame>

The modal displays a list of all your configured variables and their default values. You can modify the default values here for the current test run, but the changes do not persist outside of this modal.

<Frame>
  <img alt="" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WZ4b.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=f36c235fcb48e2dd27e9c9c99becd60c" style={{width: 496, height: 235}} width="2192" height="1038" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000005WZ4b.jpg" />
</Frame>

<Note>
  **Note:** If you want to change any default values permanently, you need to select <InlineImage src="/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GEQP.jpg" /> > **Advanced** **Edit** for that variable in the [Function Configuration](#function_configuration) section of the side navigation.
</Note>

When you are ready to test the function, select **Save and Start Function** in the modal.

If the function is successful, you receive a green toast message and a confetti GIF. If the function fails to execute properly, an error message displays in red.

Any logs from the test execution display in the **Console** area below the code editor. Any returned output from the function displays in the **Response** area.

<Frame>
  <img alt="console and response.jpg" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GEWr.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=63408e5681cb6d3579683be3da8461a0" style={{width: 900, height: 575}} width="1348" height="861" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000000GEWr.jpg" />
</Frame>

### Code Engine Library

The Code Engine library contains several useful methods specifically for making internal and external API calls, and is available in the global scope of a code engine package. You can leverage the library by adding a required "codeengine" call to your package. For more specifics about how to leverage the library see [codeengine.sendRequest](#code_engine_send_request), [codeengine.getAccount](#codeengine.getAccount), and [codeengine.axios](#code_engine_axios).

# codeengine.sendRequest

The `codeengine` library contains a method called `sendRequest` that can make calls to internal Domo APIs. `sendRequest` acts like many other http request libraries that make asynchronous calls (typically using request methods such as GET, POST, PUT, and DELETE. You can use the `sendRequest` method to call into various Domo APIs like DataSets, user and groups, and cards and dashboards.

Here is an example function that it built into the Domo DataSets package:

```javascript theme={"dark"}
const codeengine = require("codeengine");

/**
 * Retrieves the metadata for the specified dataset.
 *
 * @param dataSetId string The dataset id
 * @returns {} The dataset metadata
 */
function getDataSetMetadata(dataSetId) {
 const url = `api/data/v3/datasources/${dataSetId}?part=core,permission,status,pdp,rowcolcount,certification,functions`;

 return codeengine.sendRequest("get", url).catch(console.error);
}
```

Notice that we are making the request without any credentials like we have to do when making external calls with the axios library. Every `sendRequest` call is intercepted by the Code Engine service and injected with the credentials of the authenticated user who is making the request.

# codeengine.getAccount

This is an example function that we have built into the Twilio package that leverages the `getAccount` method from `codeengine` library. The key is this code block:

```javascript theme={"dark"}
const codeengine = require("codeengine");  
  
function accountExample(twilioAccount) {  
const account = await codeengine.getAccount(twilioAccount.id);  
const {accountSID, password} = account.properties;  
}
```

Here is how it is used in context of making an external request with the axios library also available from the `codeengine` library import:

```javascript theme={"dark"}
const codeengine = require("codeengine");  
  
async function sendSMS(twilioAccount, to, from, body) {  
// get the account by account id  
const account = await codeengine.getAccount(twilioAccount.id);  
// access the properties of the account. These will vary from account type so it's   
// important to check what is returned. In this case it's `accountSID` and `password`  
const {accountSID, password} = account.properties;  
  
const url = `https://api.twilio.com/2010-04-  
01/Accounts/${accountSID}/Messages.json?To+${to}&From=${from}&Body=${encodeURIC  
omponent(body)}`;  
  
const apiBody = {  
To: to,  
From: from,  
Body: body,  
};  
  
const requestOptions = {  
headers: {  
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',  
Authorization:  
'Basic' + Buffer.from(`${accountSID}:${password}`).toString('base64'),  
},  
};  
  
try {  
await axios.post(url, apiBody, requestOptions)';  
  
return true;  
} catch (error) {  
console.error(error);  
throw error;  
}  
}
```

The input `twilioAccount` in this example represents the account getting passed into the function at runtime. You can configure accounts by adding an input to your function setting the type as `Account`, and choosing your account type.

Select **Add Input**.

<Frame>
  <img alt="add input.jpg" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rl4w.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=d12e77fd91843d81432cdd88a3a1d1a1" style={{width: 900, height: 509}} width="2762" height="1562" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rl4w.jpg" />
</Frame>

Name your input and choose **Account** as your type.

<Frame>
  <img alt="Screenshot 2025-01-16 at 5.07.16 PM.png" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rovd.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=3622e3aa39755e82c866ab40cc15c4ab" style={{width: 350, height: 745}} width="762" height="1622" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rovd.jpg" />
</Frame>

Choosing the `Account` type opens the **Edit Parameter** modal where you can choose your account data provider.

<Frame>
  <img alt="Screenshot 2024-11-08 at 2.53.14 PM (1).png" src="https://mintcdn.com/domoinc-openapi-sync-dataflows/yCOsvW2xnTRbP1fO/images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rkjy.jpg?fit=max&auto=format&n=yCOsvW2xnTRbP1fO&q=85&s=58ce13face5c50efce2b38d8dee6e6aa" style={{width: 549, height: 305}} width="756" height="420" data-path="images/kb/ka0Vq00000089Kf-00N5w00000Ri7BU-0EMVq000004rkjy.jpg" />
</Frame>

Select **Save**. Your input is now an account strictly using the data provider you chose. When running the function in Code Engine or a workflow, the input must be from the same data provider.

# codeengine.axios

This is an example function built into the Twilio package for sending texts. It uses axios to send a post request to the Twilio API. Domo Accounts are also leveraged. For more information, see codeengine.getAccount.

```javascript theme={"dark"}
const codeengine = require(“codeengine”);

async function sendTwilioSms(to, from, body) {
  const account = await codeengine.getAccount(“Twilio”).then(a => {
    return a.properties;
  });

  const url = `https://api.twilio.com/2010-04-01/Accounts/${account.properties.SID}/Messages.json`;

  const data = new URLSearchParams();
  data.append(‘To’, to);
  data.append(‘From’, from);
  data.append(‘Body’, body);

  const requestOptions = {
    method: ‘POST’,
    headers: {
      ‘Content-Type’: ‘application/x-www-form-urlencoded;charset=utf-8’,
      ‘Authorization’: ‘Basic ‘ + Buffer.from(`${SID}:${TOKEN}`).toString(‘base64’)
    },
    data
  };

  try {
    const response = await codeengine.axios(url, requestOptions);
    const jsonResponse = await response.data;

    if (response.ok) {
      console.log('SMS sent successfully:', jsonResponse);
      return jsonResponse;
    } else {
      console.error('Error sending SMS:', jsonResponse);
      throw new Error(jsonResponse.message);
    }
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }

  return jsonResponse;
}
```
