Articles in this section

JavaScript modules overview

JavaScript modules are the libraries integrator.io makes available inside your scripts. They fall into two groups: the integrator-api module, which lets a script read and operate on the resources in your own account, and third-party modules, which are open-source libraries integrator.io imports for you. Use them when a script needs to do more than reshape the record in front of it — for example, run an export, write to a lookup cache, hash a value, or compare dates.

This section covers what each module provides and how to call it. It doesn't cover how to attach a script to a flow step; for that, see JavaScript hooks.

The integrator.io API module

The integrator-api module exposes your account's resources as runtime objects you can script against. Import the objects you need at the top of your script:

import { exports, imports, flows } from 'integrator-api'

Each runtime object supports a consistent set of methods — find(), get(), create(), update(), delete(), and others specific to the resource. Ten runtime objects are available: exports, imports, flows, connections, integrations, access tokens, async helpers, file definitions, state, and lookup caches.

The module also provides request( options ), a general-purpose function for making an HTTP request to any integrator.io API endpoint, including endpoints that have no dedicated runtime object.

For the full method-by-method reference, see integrator.io API and JavaScript runtime objects.

Third-party modules

integrator.io natively supports two open-source JavaScript libraries: sjcl for cryptographic operations and dayjs for date and time handling. You don't install them — import the library at the top of your script and call its functions.

For the supported versions and worked examples, see Third-party modules overview.

Where these modules run

Scripts that import these modules run in the integrator.io JavaScript runtime, a secure environment inside the platform. You write and test them in the script editor, which you can reach from a flow step hook, from Resources > Scripts, or from a custom API.

Two constraints apply to runtime objects specifically:

  • You can't call the create, read, update, and delete functions on runtime objects from hooks. Lookup caches are the exception.
  • A hook that calls an export, lookup, or import must belong to a flow inside an integration, not a standalone flow. To call a resource from a hook, create an integration and add your flow to it.

When to use these modules

Use the integrator-api module when a script needs to act on your account rather than only on the record passing through it. Common cases:

  • Run an export or import from inside a script, including one you define entirely in code.
  • Look up a resource by its external ID so the script keeps working after you clone a flow.
  • Store a value between flow runs using the state object.
  • Read and write lookup cache data.
  • Build a custom HTTP endpoint that calls a flow, export, or import on demand. For more on that pattern, see JavaScript API basics.

Use a third-party module when you need functionality the JavaScript language doesn't provide on its own, such as SHA-256 hashing or quarter-of-year date math.