Run the workflow on a Transactionlink-hosted page
Learn how to run a workflow on a standalone Transactionlink-hosted page with minimal frontend effort.
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;
}
app.post('/create-workflow', async (_req, res) => {
// Option 1 — Recommended: pass the organization token directly (no Bearer prefix)
const authHeader = ORG_TOKEN;
// Option 2 — Legacy (deprecated): obtain a JWT and pass it as a Bearer token
// const jwt = await authorizeWithJwt();
// const authHeader = `Bearer ${jwt}`;
const payload = {
workflowDefinitionId: WF_DEF_ID,
expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
locale: 'en',
};
const { data } = await api.post('/workflows', payload, {
headers: { Authorization: authHeader },
});
res.json({ link: data.link, workflowId: data.id });
});Set the workflow to execute
Set an expiration time
Set the interface language
2
Build your page
Obtain a redirection URL
async function getLink() {
try {
const response = await fetch('/create-workflow', { method: 'POST' });
const data = await response.json()
return data.link;
} catch (err) {
console.error(err);
throw err;
}
}Redirect to widget
<script>
async function redirectToWidget() {
window.location = await getLink();
}
document.getElementById('open-widget')
.addEventListener('click', redirectToWidget);
</script>
<!-- Button to trigger the widget -->
<button id="open-widget">Open Hosted Widget</button>let transactionLinkReady = false;
function EmbedWidget() {
const embedWidget = async (): Promise<void> => {
const token = await getToken();
if (!transactionLinkReady) {
window.transactionlink_ready = () => {
transactionLinkReady = true;
window.transactionlink!.setOptions({ token });
window.transactionlink!.open();
};
const script = document.createElement('script');
script.src = 'https://widget.transactionlink.io/transactionlink-widget.umd.js';
document.head.appendChild(script);
} else {
window.transactionlink!.setOptions({ token });
window.transactionlink!.open();
}
};
return (
<>
{/* Button to trigger the widget */}
<button onClick={embedWidget}>Open Embedded Widget</button>
<div id="transactionlink-widget" />
</>
);
}Last updated