# Get started with functions

## Overview

A Rippling Function is JavaScript code written by you, but saved, deployed, versioned, and run in an isolated environment managed by Rippling.

Functions are useful when you want to perform multiple actions to streamline a process, especially when you want to leverage data stored in your Rippling account. One advantage of using a function is that you don't have to set up your own infrastructure to run your code, which streamlines and simplifies the development process.

For example, in just a few minutes, you can quickly create and deploy a function that performs a quarterly calculation for your Sales team or updates your CRM with data collected in a third-party system or custom application.

### What can a function do?

| Operation | Example |
| --- | --- |
| Perform calculations and return results | Calculate a store's total sales for a specific date range |
| Execute conditional logic and loops | If the function was called from a list view, iterate over the records, otherwise use the record\_id |
| Process and manipulate data | Reformat data from a third-party so it can be received by the Rippling APIs |
| Call Rippling APIs | Save data to a Rippling custom object |
| Call third-party APIs | Combine data from a third-party API with Rippling data |

> **Note:**
> See [When to use Rippling primitives](https://developer.rippling.com/documentation/rippling-platform/custom-solutions/rippling-primitives) for more information on when to use functions vs. automations or transformations.

* * *

## Requirements

-   Permission to **Create functions**, **Manage functions in the Developer app**, or **Create custom apps and custom objects**. For more information, see [Permissions for the Developer app](https://developer.rippling.com/documentation/rippling-platform/developer/permissions).
-   [Custom objects](https://help.rippling.com/article?articleId=913659176072#what-is-a-custom-object) - You must create at least one object and populate it with data.
-   [API token](https://developer.rippling.com/documentation/rippling-platform/developer/api-tokens#create) - Required if calling the Rippling APIs. Generate your token in the **Developer** app under the _API Tokens_ tab, and save it for later use.

* * *

## Create a new function

1.  From the sidebar, select **Tools > Developer**.
2.  Select the **Functions** tab and click **New**.
3.  Name the function, give an optional description, and confirm whether the function should **run asynchronously**.

> **Execution mode cannot be changed:**
> The execution mode (`is_async`) is fixed when you create the function. You cannot change an asynchronous function to synchronous, or a synchronous function to asynchronous. To use a different execution mode, create a new function.

### Asynchronous functions

Use the asynchronous option for functions with long-running work, such as payroll staging, bulk custom-object updates, external API pagination, backfills, large transformations, report generation, or automation-triggered processing that can safely complete in the background. Asynchronous functions can be executed through automations, UI triggers, or the [Create a new function execution](https://developer.rippling.com/documentation/rest-api/reference/create-functions-function-api-name-executions) API endpoint.

Avoid running a function asynchronously for interactions where the user needs an immediate result (unless the function writes progress/status to a custom object and the UI can display this information). A function used as a **custom pipeline stream** should stay synchronous so it can return `DataBridgeResponse` to DataBridge.

> **SDUI functions must be synchronous:**
> A function used for an [SDUI function page](https://developer.rippling.com/documentation/rippling-platform/sdui/getting-started) must always run synchronously (`is_async: false`) so the page receives the SDUI spec and server round-trip results directly. Leave **run asynchronously** disabled when creating the function. This execution setting is separate from using JavaScript `async`/`await` in your code.

### Function anatomy

Rippling provides a template for your function code, so all you need to do to write your first function is add your custom logic. We suggest leaving the template code in place to simplify the process. The template includes:

-   `Imports` - Helper libraries that will make your life easier. We currently support:
    -   lodash - Includes various JavaScript utilities.
    -   moment - Handles dates and times.
    -   Rippling SDK - Calls the Rippling APIs.
-   `Inputs` (Required) - The data that is passed into the function.
    -   `event` - contains information about the source of the invocation; most used (events.recordId(s), event.currentUser).
    -   `context` - contains information about the runtime environment.
-   `Custom logic` (Your code goes here!) - The logic that tells your function what to do.

> 💡 **Tip** Use comments to increase readability.

```text
// This is a one line comment

/* 
  This is a 
  multiline 
  comment 
*/
```

-   `Output` - The response you want returned after the function is invoked. The supported response codes are:
    -   **200 (OK)** - Displays your message in a green box.
    -   **400 (Error)** - Displays your message in a red box.
    -   **301 (Redirect)** - Redirects to a new location.

![Function](https://developer.rippling.com/assets/images/Anatomy-1a2769a5cc182533db4c0790ee561ccd.png)

### Authentication

**Use an API key stored in a custom setting**

Replace `YOUR_BEARER_TOKEN` with your API key from the Developer app.

We recommend storing the API key in a [custom setting](https://developer.rippling.com/documentation/rippling-platform/developer/custom-settings) and referencing it at runtime.

Use when:

-   Your function runs outside of an interactive user session (e.g., automations or background execution).
-   You need consistent, service-level permissions that aren’t tied to a specific end user.
-   The function must run even when no user is actively logged in.

> **Security considerations:**
> The API key grants access based on the permissions configured in the Developer app. If the key is compromised, anything within its permission scope may be accessed. You are also responsible for managing key rotation and access control.

Using a **custom setting** helps ensure the API key is not exposed directly in code and can be managed securely:

```json
const token = context.settings["my_api_key"];
const ripplingSDK = new RipplingSDK({ bearerToken: token });
```

**Use the invoking user’s bearer token**

You can configure the function to use the bearer token of the person invoking it. In this case, requests run as the currently logged-in user.

Use when:

-   The function is invoked from the UI.
-   Actions should be scoped to the permissions of the logged-in user.
-   You want enforcement of user-level access control.

Requirements:

-   The function must be triggered from the UI so the system can determine the authenticated user.

> **Security considerations:**
> The function runs with the permissions of the invoking user and it must be triggered from the UI. It is not appropriate for unattended automations or background jobs, and the behavior can vary depending on who invokes it and what access they have.
>
> The function will execute with the **privileges of the user who triggers it** — which may exceed those of the function’s author. For example, if a Super Admin invokes the function, it runs with Super Admin permissions. Make sure to explicitly validate authorization logic to prevent unintended privilege escalation.

```json
const rippling = new RipplingSDK ({ bearerToken: context.env.rippling_user_bearer_token });
```

Choose the approach that matches how your function runs and the access boundaries you want to enforce.

### Sample input

The schema of the `FunctionEvent` object depends on the context from which it's invoked.

**Custom object list view:**

```json
{
    "object_api_name": "pet__c",
    "record_ids": ["<object_id>", "<object_id>"],
    "current_user": "<object_id>",
    "app_id": "<object_id>",
    "list_view_id": "<object_id>",
    "page_id": "<object_id>",
    "button": "my_cool_button",
    "url": "https://app.rippling.com/custom-apps/objects/rto_expectation__c?app=rto_hub", 
    "trigger_type": "list view",
}
```

**Custom object detail view:**

```json
{
    "object_api_name": "pet__c",
    "record_id": "<object_id>",
    "current_user": "<object_id>",
    "app_id": "<object_id>",
    "layout_id": "<object_id>",
    "button": "my_cool_button",
    "url": "https://app.rippling.com/custom-apps/objects/rto_expectation__c?app=rto_hub",
    "trigger_type": "detail view",
}
```

* * *

## Deploy a function

**Deploy** your function to save and use it immediately, or **Save** and deploy later from the **Code** tab.

![Save And Deploy](https://developer.rippling.com/assets/images/SaveAndDeployButton-303563145d763267ba1f9c4ab57e75f8.png)

### View deployment logs

You can view deployment history from the **Deployments** tab. Each deployment includes details such as the deployment timestamp, the user who initiated the deployment, and the current deployment status.

![Deployments](https://developer.rippling.com/assets/images/Deployments-b04f05a8b9772703c1862f13cbe11d7a.png)

### Compare deployment versions

To compare deployment versions, select a deployment and open the **Code** tab. Use the version dropdown to choose another deployment and view a side-by-side diff of the function code changes between versions. This can help identify what changed across deployments and assist with troubleshooting issues introduced in recent updates.

![Diffs](https://developer.rippling.com/assets/images/Diffs-76027c8b8fcd861b448390f8d326cabb.png)

* * *

## Test a function

Once your code has been deployed, you can easily test it using debug statements, the built-in testing tool, and the logs.

### Add debug statements

You can use `console.log` to debug your code and see how your function is manipulating the data:

```json
console.log(“Your message goes here.”);
```

![Debug Statement](https://developer.rippling.com/assets/images/DebugStatement-f41ee1ebe891a9a1d08f430ff4e335cf.png)

> **Note:**
> Log the data before and after modifying it, so you can compare.

```json
console.log("The data before: " + data);
data = doSomething(data);
console.log("The data after: " + data);
```

### Use the testing tool

Test your function from the **Code** tab using the built-in testing tool.

> **Note:**
> The function must be **deployed** to be tested.

![Test Function](https://developer.rippling.com/assets/images/TestFunctionButton-834d5ce4d42bcd06cf68af464c5f8ea5.png)

1.  Choose an input template - **List view** or **Detail view**.
2.  Edit your input values. You can also copy input values from the log to reproduce specific scenarios.

![Test Input](https://developer.rippling.com/assets/images/TestInput-0974ac494a3506fc6897037cb9f29064.png)

3.  **Run** the test.
4.  Check the **output** and **logs**.

![Test Output](https://developer.rippling.com/assets/images/TestOutput-b4d6e99e02998d00129a104b4502d821.png)

* * *

## Additional information

### View execution logs

The execution logs provide information about each time the function was invoked. They can be helpful for auditing and recreating specific scenarios.

![Logging](https://developer.rippling.com/assets/images/Executions-7189c31a82621c3f1bd6ecc67a1ea7ca.png) ![Logging](https://developer.rippling.com/assets/images/ViewExecution-75f484c358b59ea6136044642c70f153.png)

### Manage access

You can set permissions for your function under **Manage access**.

To let other people view your [SDUI function page](https://developer.rippling.com/documentation/rippling-platform/sdui/getting-started), grant them both **Viewer** and **Runner** access to the function that backs the page.

![Manage Access Button](https://developer.rippling.com/assets/images/ManageAccessButton-2ebc4fd795c5c34100fdb84fb9f90de3.png)

-   **Runner** - Can execute the function.
-   **Viewer** - Runner privileges, plus user can view the function code.
-   **Editor** - Runner and Viewer privileges, plus user can edit and deploy the function code, view execution logs, and manage access.

> **Note:**
> If you are not a Runner, the action will not be visible in your UI.

You can give access to individual people or use Supergroups to assign access automatically based on people’s attributes.

-   **Include** - Provides access to those listed.
-   **Except** - Removes access from those listed.

In this example, the user who created the function is the only person who can edit it. The creator and anyone in the Engineering department can view it, and everyone in the company except for temporary employees and contractors can run it.

![Manage Access Page](https://developer.rippling.com/assets/images/ManageAccess-0da7a83b976f673513abe78386361b2c.png)

You can also use the `AND` operator to filter groups by multiple criteria. For more information about managing access using Supergroups, see our [Help Center article](https://help.rippling.com/article?articleId=53273402848).

![Assign Permissions](https://developer.rippling.com/assets/images/IncludeExclude-9488304f4566dabc5d3550a4412c4093.png)

> **Note:**
> You can save groups to be used in other functions.

![Save Group](https://developer.rippling.com/assets/images/SaveGroup-516fd15ec4ea93cc13d3cc2e99f496cd.png)

### Download function code

If you would prefer to develop locally in your IDE rather than in the browser, you can download the source code to a .zip file by clicking the **Code** button.

![Download Function](https://developer.rippling.com/assets/images/DownloadFunction-1ae125713e4486b4d22e45690920c15a.png)

### Update allowed domains

Setting allowed domains gives you control over which endpoints your function can call. This security feature ensures the code will not send requests to places you don't know about.

![Allowed Domains Button](https://developer.rippling.com/assets/images/AllowedDomainsButton-b6c3ae6882dcf2d638b90d4500173a9b.png) ![Update Allowed Domains](https://developer.rippling.com/assets/images/AllowedDomains-2025d19f12cfeb59fcb4e2905fc9fd18.png)

> **Calling your own APIs?**
> If your function makes API calls to your own endpoints that restrict incoming traffic to specific IP addresses, you'll need to add the following Rippling IP addresses to your allowlist:
>
> -   `52.11.37.165`
> -   `54.70.121.88`
> -   `54.214.241.136`
>
> All HTTP requests from Rippling Functions originate from these IP addresses.

### Update timeout

The timeout determines how long a function will run before stopping. The default runtime for Rippling functions is 20 seconds, but you can set custom timeout lengths for each function using the UI.

![Update Timeout Button](https://developer.rippling.com/assets/images/TimeoutButton-be222eaf9254df80fb12a55151165c92.png) ![Update Timeout](https://developer.rippling.com/assets/images/Timeout-d9e02db62696b16ffb61317168f37639.png)

### Dependencies

Dependencies allow you to use other open source libraries in your function. You can include any package from the public npm repository.

![Dependencies Button](https://developer.rippling.com/assets/images/DependenciesButton-ee628aa1f4a2069d517739b8f48906d6.png)

* * *

## See also

-   [Rippling API Docs](https://developer.rippling.com/documentation/rest-api)
-   [Rippling JavaScript SDK Docs](https://developer.rippling.com/documentation/js-sdk)
-   [Postman](https://www.postman.com/)
-   [Code Academy Javascript Tutorial](https://www.codecademy.com/learn/introduction-to-javascript)

Source: https://developer.rippling.com/documentation/rippling-platform/developer/functions/getting-started

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
