# Headless JavaScript

> Build your own interface with the typed client and use the public API for format-specific completion evidence.

Source: https://dashboard.adquest.batriders.ir/docs/headless · Audience: Developers · Section: Build

## Prerequisites

- The SDK installed: npm install @adquest/sdk.
- Your public API key, API URL and a participant token for the user.

## Initialize the client

**Client setup**

```typescript
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);
```

> **Names and user changes.** Use getQuest(id) for detail and getQuestStats(id) for platform-scoped engagement. Recreate application state when the user changes. API fields are snake_case. SDK models use camelCase.

## Question-based quest sessions

1. Start the selected quest. Use requiresTimer: false for a survey. For a video, pass watchDuration and feed real playback into syncMediaProgress(elapsed, total).
2. For timed media, wait for session.waitForDuration(). Render the question / questions returned by getQuestion() or getQuestions().
3. Submit the participant’s chosen option ID with session.complete(optionId), or a SurveyAnswerInput[] for a multi-question survey.
4. Check result.status and the returned settlement state before showing rewards. Unsubscribe from progress listeners when the view unmounts.

> **Complete the format you started.** QuestSession.complete accepts the option the participant chose. Do not auto-select an answer. Visit, event, profile, referral, and custom quests use evidence instead of a question. Streak days are not completed through QuestSession.complete or POST /platform/quests/{id}/complete. Copy the generated callback URL and call it from your backend with the user id.

## 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.

- [Quest evidence](https://dashboard.adquest.batriders.ir/docs/quest-evidence): The request helper and the API calls for every quest format.

## Client methods

Every client method has a signature, parameters and an example in the SDK reference.

- [Client](https://dashboard.adquest.batriders.ir/docs/sdk/client): Create the client, set the user and token.
- [Quest methods](https://dashboard.adquest.batriders.ir/docs/sdk/quests): List, start and complete quests.
- [Reward methods](https://dashboard.adquest.batriders.ir/docs/sdk/rewards): Balance, lotteries and claims.

## Next steps

- [Quests API](https://dashboard.adquest.batriders.ir/docs/api/quests): Request and response details for each route.
- [Tokens, lotteries & claims](https://dashboard.adquest.batriders.ir/docs/rewards): Balances, entries and claims.
- [API reference](https://dashboard.adquest.batriders.ir/docs/api-reference): Authentication, headers and the response format.
