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';
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());
async function authorize() {
const {data} = await api.post('/auth/authorize', {key: KEY, secret: SECRET});
return data.accessToken;
}
app.post('/create-workflow', async (_req, res) => {
const accessToken = await authorize();
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: `Bearer ${accessToken}`},
});
res.json({token: data.token, workflowId: data.id});
});
app.get('/workflow-status', async (req, res) => {
const workflowId = req.query.workflowId;
const accessToken = await authorize();
const {data} = await api.get(`/workflows/${workflowId}`, {
headers: {Authorization: `Bearer ${accessToken}`}
}).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