Use the JavaScript SDK
The SDK is a lightweight client for the browser and Node. With it you connect your own landing page or website to a campaign, the member portal or the public API without writing the HTTP calls.
1. Install the SDK
With a script tag, from your platform:
<script src="https://<your-platform>/sdk/incentia.js"></script>
Or as a package, if IncentIA gave it to you (@incentia/sdk, with TypeScript types):
import { IncentIA } from '@incentia/sdk';
2. Create the client
const ia = new IncentIA({ baseUrl: 'https://<your-platform>' });
| Option | Purpose |
|---|---|
baseUrl | Required. Your platform's address |
apiKey | An mk_... key, server only |
programId | Default programme for member operations |
onTokenExpired | Function called when the member token expires (401) |
Anyone can read your site's code. Use apiKey only on your server. Landing pages use ia.campaigns and ia.auth, which need no key.
3. Take part in a campaign from your landing page
<script>
const ia = new IncentIA({ baseUrl: 'https://<your-platform>' });
ia.campaigns.getStatus('summer-2026').then(data => {
document.getElementById('title').textContent = data.campaign.name;
});
document.getElementById('form').onsubmit = async (e) => {
e.preventDefault();
const result = await ia.campaigns.register('summer-2026', {
email: document.getElementById('email').value,
firstName: document.getElementById('name').value,
marketingOptIn: true,
});
if (result.hasGame) {
const play = await ia.campaigns.play('summer-2026', { participantId: result.participantId });
alert(play.prizeName ? `You won ${play.prizeName}!` : 'Better luck next time');
}
};
</script>
4. Sign in as a member (OTP)
await ia.auth.sendOtp({ phone: '+34600111222', programId: 1 });
const auth = await ia.auth.verifyOtp({ phone: '+34600111222', code: '123456' });
const dashboard = await ia.portal.getDashboard();
verifyOtp stores the token. To restore a session use ia.setMemberToken(token).
5. Call the public API from your server
const ia = new IncentIA({ baseUrl: 'https://<your-platform>', apiKey: process.env.INCENTIA_KEY });
const member = await ia.members.lookup({ programId: 1, phone: '+34600111222' });
await ia.transactions.purchase({
memberId: member.memberId, programId: 1, amount: 49.99, externalReference: 'ORDER-12345',
});
Modules
| Module | Access | Main methods |
|---|---|---|
ia.campaigns | Public | getStatus, register, play |
ia.auth | Public | resolve, register, sendOtp, verifyOtp, loginGoogle, loginApple, refresh |
ia.portal | Member token | getDashboard, getRewards, redeemReward, getGames, playGame, getStamps, checkin, submitEvidence… |
ia.members | API key | lookup, getBalance, getTransactions |
ia.transactions | API key | purchase, action, redeem, adjust |
ia.coupons | API key | validate, redeem |
ia.whitelabel | Public | resolve, getLanding, getCampaignLanding |
Routes and fields for the API-key modules are those of the public API.
Errors
Every method returns a promise. On failure the error carries status, message and details:
try { await ia.portal.redeemReward(99); }
catch (err) { if (err.status === 400) alert(err.message); }
Check that it works
Open the browser console: ia.campaigns.getStatus('<your-slug>') should return the campaign data. A CORS error means your domain is missing from the allowed origins.
Next steps
- Campaign embed and ranking, if you prefer not to write code.
- Public API v1