// Travlix API v1 - signed request in Node.js 18+ (built-in fetch). Usage: TLX_KEY=... TLX_SECRET=... node sign.js const crypto = require('crypto'); const BASE = process.env.TLX_BASE || 'https://api.travlix.com'; const KEY = process.env.TLX_KEY, SECRET = process.env.TLX_SECRET; async function tlxCall(method, path, body, headers = {}) { const raw = body === undefined ? '' : JSON.stringify(body); const u = new URL(path, BASE); const ts = String(Math.floor(Date.now() / 1000)); const nonce = crypto.randomBytes(16).toString('hex'); const sts = [method.toUpperCase(), u.pathname, u.search.replace(/^\?/, ''), ts, nonce, crypto.createHash('sha256').update(raw).digest('hex')].join('\n'); const sig = crypto.createHmac('sha256', SECRET).update(sts).digest('hex'); const res = await fetch(u, { method, body: method === 'GET' ? undefined : raw, headers: { 'Content-Type': 'application/json', 'X-Api-Key': KEY, 'X-Timestamp': ts, 'X-Nonce': nonce, 'X-Signature': sig, ...headers } }); return [res.status, await res.json()]; } (async () => { console.log('balance', ...(await tlxCall('GET', '/v1/wallet/balance'))); const date = new Date(Date.now() + 30 * 864e5).toISOString().slice(0, 10); const [code, r] = await tlxCall('POST', '/v1/flight/search', { origin: 'DEL', destination: 'BOM', departure_date: date, adults: 1 }); console.log('search', code, r.data && r.data.count, 'offers'); if (r.data && r.data.offers.length) { const [c2, q] = await tlxCall('POST', '/v1/flight/fare-quote', { offer_id: r.data.offers[0].offer_id }); console.log('fare-quote', c2, q.data && q.data.price.total); } })();