Headless JavaScript
Build your own interface with the typed client and use the public API for format-specific completion evidence.
On this page
Prerequisites
- The SDK installed: npm install @adquest/sdk.
- Your public API key, API URL and a participant token for the user.
Initialize the client
import { createAdQuestClient } from "@adquest/sdk";
const client = createAdQuestClient({
apiKey: "YOUR_PUBLIC_API_KEY",
baseUrl: "https://api.adquest.batriders.ir/api/v1",
externalUserId: "host-user-123",
participantToken: "TOKEN_FROM_YOUR_BACKEND",
});
const quests = await client.getQuests();
// Render quests and let the participant choose one.
// On token refresh: client.setParticipantToken(newToken);Question-based quest sessions
Start the selected quest. Use requiresTimer: false for a survey. For a video, pass watchDuration and feed real playback into syncMediaProgress(elapsed, total).
For timed media, wait for session.waitForDuration(). Render the question / questions returned by getQuestion() or getQuestions().
Submit the participant’s chosen option ID with session.complete(optionId), or a SurveyAnswerInput[] for a multi-question survey.
Check result.status and the returned settlement state before showing rewards. Unsubscribe from progress listeners when the view unmounts.
Send format-specific API requests
Evidence quests (visit, event, profile, referral, streak and custom) use the public API directly. The shared request helper and each format’s calls are in Quest evidence.
Client methods
Every client method has a signature, parameters and an example in the SDK reference.