Skip to main content

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.

Before you start
  • A campaign with its URL identifier (slug) if you will participate from a landing page.
  • An API key only for calls from your server.
  • Your domain in the key's Allowed Origins or in the platform's CORS configuration.

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>' });
OptionPurpose
baseUrlRequired. Your platform's address
apiKeyAn mk_... key, server only
programIdDefault programme for member operations
onTokenExpiredFunction called when the member token expires (401)
Do not publish your API key in the browser

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​

ModuleAccessMain methods
ia.campaignsPublicgetStatus, register, play
ia.authPublicresolve, register, sendOtp, verifyOtp, loginGoogle, loginApple, refresh
ia.portalMember tokengetDashboard, getRewards, redeemReward, getGames, playGame, getStamps, checkin, submitEvidence…
ia.membersAPI keylookup, getBalance, getTransactions
ia.transactionsAPI keypurchase, action, redeem, adjust
ia.couponsAPI keyvalidate, redeem
ia.whitelabelPublicresolve, 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​