Appearance
Dataport Script Reference: Dataport API
context.dataport provides authenticated access to the Dataport REST API and WebSocket webhooks. All HTTP methods use your current account's credentials automatically.
HTTP Methods
get()
Performs an authenticated GET request to the Dataport API.
Signature: get(partial: string): Promise<any>
partial— URL path relative to the Dataport API base, e.g./api/v1/sessions- Returns parsed JSON, or plain text if the response is not JSON
Example:
js
const session = await context.dataport.get(`/api/v1/sessions/${context.session.id}?accountId=${context.accountId}`)
context.log(session.status)post()
Performs an authenticated POST request to the Dataport API.
Signature: post(partial: string, body: object): Promise<any>
Example:
js
const session = await context.dataport.post(`/api/v1/sessions?accountId=${context.accountId}`, {
accountId: context.accountId,
projectId: context.session.projectId,
programId: context.session.programId,
workspaceId: context.session.workspaceId,
name: 'My Session',
})put()
Performs an authenticated PUT request to the Dataport API.
Signature: put(partial: string, body: object): Promise<any>
Example:
js
await context.dataport.put(`/api/v1/sessions/${context.session.id}?accountId=${context.accountId}`, {
status: 'completed',
})del()
Performs an authenticated DELETE request to the Dataport API.
Signature: del(partial: string): Promise<true | null>
Example:
js
await context.dataport.del(`/api/v1/sessions/${sessionId}?accountId=${context.accountId}`)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