Show each buyer only their own data
Build a buyer area on your own site without leaking other buyers' records or your margins.
If your own website lets buyers sign in, each buyer must see only their own calls and leads, and never your publisher payouts or margins. An Account API key can see the whole account, so the care is on your side.
Today: filter and trim on your server
- Look up the signed-in buyer's TRAKI ID on your server, from your own session. Never take it from the page or the address: a buyer could change it.
- Always pass it as a filter. Every list that a buyer sees gets
buyerId:
curl 'https://api.traki.io/v1/account/calls?buyerId=0b6c3d1e-9a4f-4e2b-8d7c-5f1a2e3b4c6d&limit=25' \
-H "Authorization: Bearer $TRAKI_KEY"- Remove fields the buyer must not see before you send the answer to the page. A call answer from the Account API carries
publisherPayoutand the publisher's name; a buyer should get neither. - Check single records too. When a buyer opens one call, fetch it and confirm its
buyer.idis theirs before you show it.
const ALLOWED = [
'id',
'code',
'campaign',
'caller',
'startedAt',
'endedAt',
'durationSec',
'billable',
'buyerCharge',
];
function forBuyer(call, buyerId) {
if (call.buyer?.id !== buyerId) return null; // not theirs: answer "not found"
return Object.fromEntries(ALLOWED.map((k) => [k, call[k]]));
}Safer: ask as the buyer, with Traki-On-Behalf-Of
When your server fetches data for one buyer, call the Buyer API route with your Account API key and add:
GET /v1/buyer/calls
Authorization: Bearer traki_account_live_…
Traki-On-Behalf-Of: buyer:<id>TRAKI then answers exactly as it would answer that buyer's own key: the same hidden fields, the same sharing settings, the same limits. A mistake in your code can no longer show a buyer your payouts or margins, so you can drop the trimming above.
- Reading needs
buyers:readon your key; changing (a bid, a return) needsbuyers:write. - The header works only on Buyer API routes (
publisher:<id>on Publisher API routes) and only narrows. A buyer of another account answersnot_found; a malformed header answerson_behalf_invalid. - Your request log shows which buyer each request was made for.
From the browser: portal sessions
If you would rather your web page call TRAKI directly, ask your server for a session token for the signed-in buyer and hand only that token to the page:
POST /v1/account/portal-sessions
Authorization: Bearer traki_account_live_…
Content-Type: application/json
{ "party": "buyer:<id>", "origins": ["https://portal.example.com"] }The answer holds a traki_session_… token that:
- works only on that buyer's Buyer API routes, read-only unless you ask for
"access": "read_write"(which needsbuyers:write); - works only from the origins you name, which are the only sites the API sends cross-site headers to;
- ends after 15 minutes (or sooner with
ttlSeconds), when you callDELETE /v1/account/portal-sessions/{id}, or when the key that asked for it is revoked.
Never put an account key in a page. The responsibility for asking for the right buyer stays with you; see security and responsibilities.