Run the workflow inside your application
Learn how to render the workflow directly inside your application using an iframe for a seamless user experience.
1
Set up the server
Create a Workflow Execution
const express = require('express');
const axios = require('axios');
const API_BASE = process.env.API_BASE ?? 'https://api.transactionlink.io';
// --- Recommended: organization token (tot_) ---
const ORG_TOKEN = process.env.ORG_TOKEN ?? 'tot_<your-organization-token>';
// --- Legacy: workspace credentials (JWT) — deprecated, will be removed in a future release ---
const KEY = process.env.KEY ?? '<your-key>';
const SECRET = process.env.SECRET ?? '<your-secret>';
const WF_DEF_ID = process.env.WF_DEF_ID ?? '<your-workflow-definition-id>';
const api = axios.create({ baseURL: API_BASE });
const app = express();
app.use(express.json());
// Legacy: obtain a JWT access token using workspace credentials.
// Deprecated in favor of organization tokens (tot_).
async function authorizeWithJwt() {
const { data } = await api.post('/auth/authorize', { key: KEY, secret: SECRET });
return data.accessToken;
}
// Returns the Authorization header value for the current auth strategy.
// Switch to the legacy option below if you haven't migrated to organization tokens yet.
function getAuthHeader() {
// Recommended: pass the organization token directly (no Bearer prefix)
return ORG_TOKEN;
// Legacy (deprecated): obtain a JWT and pass it as a Bearer token
// const jwt = await authorizeWithJwt();
// return `Bearer ${jwt}`;
}
app.post('/create-workflow', async (_req, res) => {
const payload = {
workflowDefinitionId: WF_DEF_ID,
expiresAt: new Date(Date.now() + 61 * 60 * 1000).toISOString(),
locale: 'en',
};
const { data } = await api.post('/workflows', payload, {
headers: { Authorization: getAuthHeader() },
});
res.json({ token: data.token, workflowId: data.id });
});
app.get('/workflow-status', async (req, res) => {
const workflowId = req.query.workflowId;
const { data } = await api.get(`/workflows/${workflowId}`, {
headers: { Authorization: getAuthHeader() },
}).catch(reason => console.log(reason));
res.json({ status: data.status, workflowId: data.id });
});
app.listen(8080, () => console.log('Running on port 8080'));Set the workflow to execute
Set an expiration time
Set the interface language
2
Build your page
Create HTML element for widget
<transactionlink-widget />Obtain an ID and a token
async function createWorkflowExecution() {
try {
const response = await fetch('/workflow-execution', { method: 'POST' });
const data = await response.json()
return data;
} catch (err) {
console.error(err);
throw err;
}
}Initialize widget
Await for workflow status (optional)
PreviousRun the workflow on a Transactionlink-hosted pageNextRun the workflow as a background process
Last updated