Appearance
Dataport Script Reference: Dataport API
context.dataport provides authenticated access to the Dataport REST API and WebSocket webhooks.
Session Management
createSession()
Creates a new Dataport session via the API.
Signature: createSession(payload: object): Promise<any>
Payload:
js
{
accountId: string,
projectId: string,
programId: string,
workspaceId: string,
workspaceVersionId?: string,
name?: string,
}Example:
js
const newSession = await context.dataport.createSession({
accountId: context.accountId,
projectId: context.session.projectId,
programId: context.session.programId,
workspaceId: context.session.workspaceId,
name: 'Parallel session',
})
context.log(newSession.id)getSession()
Fetches a session by ID.
Signature: getSession(sessionId: string): Promise<any>
Example:
js
const session = await context.dataport.getSession('abc123')
context.log(session.status)getSessions()
Fetches all sessions for the current workspace.
Signature: getSessions(): Promise<any[]>
Example:
js
const sessions = await context.dataport.getSessions()
const active = sessions.filter(s => s.status === 'inprogress')
context.log(`${active.length} active sessions`)updateSession()
Updates an existing session.
Signature: updateSession(payload: object): Promise<any>
The payload must include the session id.
Example:
js
await context.dataport.updateSession({
id: context.session.id,
status: 'completed',
})deleteSession()
Deletes a session by ID.
Signature: deleteSession(sessionId: string): Promise<true | null>
Example:
js
await context.dataport.deleteSession('abc123')Webhooks
subscribeToWebhook()
Opens a WebSocket connection to receive webhook payloads for a specific workflow node. The connection is automatically reused if a subscription already exists for the same node.
Signature: subscribeToWebhook(workflowId: string, nodeId: string, callback: (error: null, payload: any) => void): WebSocket
Example:
js
context.dataport.subscribeToWebhook(
'workflow-node-id',
'webhook-node-id',
(error, payload) => {
context.log('Webhook received:', payload)
}
)INFO
The callback only receives payloads whose programId matches the current session's programId, or '*' for broadcast webhooks.
unsubscribeFromWebhook()
Closes the WebSocket connection for a specific workflow node.
Signature: unsubscribeFromWebhook(workflowId: string, nodeId: string): void
Example:
js
context.dataport.unsubscribeFromWebhook('workflow-node-id', 'webhook-node-id')clearWebhookSubscriptions()
Closes all active webhook WebSocket connections.
Signature: clearWebhookSubscriptions(): void
Example:
js
context.dataport.clearWebhookSubscriptions()encodeWebhookId()
Encodes a webhook identifier into a base62 string. Useful when constructing webhook URLs manually.
Signature: encodeWebhookId(options: object): string
Options:
js
{
workflowId: string, // required
nodeId: string, // required
accountId?: string, // defaults to current account
workspaceId?: string, // defaults to current workspace
}Example:
js
const channelId = context.dataport.encodeWebhookId({
workflowId: 'my-workflow-id',
nodeId: 'my-webhook-node-id',
})
context.log(channelId) // base62 encoded string