Skip to content

Dataport Script Reference: General

context.accountId

The account ID of the current Ease Live account.

Type: string

Example:

js
context.log(context.accountId) // 'myaccount'

context.session

The current runtime session.

Type:

js
Object {
  id: string,
  name: string,
  type: 'session',
  mode: 'importer' | 'scheduler',
  projectId: string,
  programId: string,
  workspaceId: string,
  status: 'inprogress' | 'completed' | 'cancelled',
  startedAt: string, // ISO 8601
  createdAt: string, // ISO 8601
  on: (event: string, callback: Function) => void,
  off: (event: string, callback: Function) => void,
  emit: (event: string, payload: any) => void,
}

Example:

js
context.log(context.session.status)   // 'inprogress'
context.log(context.session.programId) // 'abc123'

// Listen for custom events emitted from other scripts
context.session.on('my-event', (payload) => {
  context.log('received', payload)
})

context.env

Environment variables defined in the workspace. Reads from the active environment first, falls back to the global environment. Supports both reading and writing.

Type: Proxy<Object>

Example:

js
// Read a variable by name
const apiKey = context.env.MY_API_KEY

// Write a variable
context.env.MY_API_KEY = 'new-value'

context.sources

Data sources available in the workspace. Look up sources by name or ID.

Type: Proxy<Object>

Example:

js
const mySource = context.sources['My Source']
context.log(mySource.data)

context.workflows

All workflow node definitions in the workspace, keyed by node ID.

Type: Object

Example:

js
const workflow = Object.values(context.workflows).find(n => n.description === 'My Workflow')
context.log(workflow?.id)

context.activities

All activities executed in the current session. Each activity represents one node execution.

Type:

js
Array<{
  id: string,
  activityId: string,
  nodeId: string,
  parent: string,
  previousActivityId: string,
  workflowActivityId: string,
  name: string,
  type: string,           // node type, e.g. 'httpRequest', 'callFunction'
  status: 'inprogress' | 'completed' | 'failed' | 'cancelled',
  triggeredBy: string | null,
  createdAt: string,      // ISO 8601
  startedAt: string,      // ISO 8601
  updatedAt: string,      // ISO 8601
  finishedAt: string,     // ISO 8601
  log: string[],
  data: {
    // Set by nodes that produce output — shape varies by node type:
    // httpRequest:   { request, response: { status, headers, body }, error }
    // callFunction:  { response: any, error: string }
    // aiPrompt:      { request, response, error }
    // filter/sort:   { response: any[] }
    // find:          { response: any }
    // reduce/edit:   { response: object }
    // uploadImage:   { response: { url: string } }
    // getProgram:    { response: Program }
    response?: any,
    error?: any,
  },
  // Loop-related (only present when activity is inside a loop)
  iteratorId?: string,
  iteratorActivityId?: string,
  iterationId?: string,
}>

INFO

data and log are in-memory only and are not persisted to the database.

Example:

js
const failed = context.activities.filter(a => a.status === 'failed')
context.log(`${failed.length} failed activities`)

// Access a specific node's response
const httpActivity = context.activities.findLast(a => a.type === 'httpRequest')
context.log(httpActivity?.data?.response?.body)

context.shared

A shared mutable object available to all nodes within the same session. Useful for passing data between workflows without chaining.

Type: Object

Example:

js
// In one script
context.shared.counter = (context.shared.counter ?? 0) + 1

// In another script later in the session
context.log(context.shared.counter) // 1

context.node

The current node's configuration object.

Type:

js
Object {
  id: string,
  type: string,
  description: string,
  activityId: string,
  // ... other node properties
}

Example:

js
context.log(context.node.description) // 'My Call Function node'

context.prev

The activity that directly preceded the current node in the execution chain.

Type: Activity | undefined — see context.activities for the activity shape.

Example:

js
// Access the previous node's response
const result = context.prev?.data?.response
context.log(result)

context.lodash

The Lodash utility library.

Example:

js
const { groupBy, orderBy } = context.lodash
const grouped = groupBy(items, 'category')

context.date

The date-fns date utility library.

Example:

js
const { format, addDays, parseISO } = context.date
const tomorrow = addDays(new Date(), 1)
context.log(format(tomorrow, 'yyyy-MM-dd'))

context.crypto

The Web Crypto API.

Example:

js
const array = new Uint8Array(16)
context.crypto.getRandomValues(array)
const hex = Array.from(array).map(b => b.toString(16).padStart(2, '0')).join('')
context.log(hex) // random hex string

context.ws

The WebSocket constructor for creating raw WebSocket connections.

Example:

js
const socket = new context.ws('wss://example.com/ws')
socket.onmessage = (event) => {
  context.log('received:', event.data)
}