Client
Create the typed AdQuest client and set the user, token and host context.
On this page
Install
npm install @adquest/sdkThe client lives in @adquest/sdk. The React components are in @adquest/sdk/react. Every method returns a Promise and throws an AdQuestError on failure.
Create a client
Creates a client for one platform. Call setUser and setParticipantToken when the signed-in user changes.
function createAdQuestClient(config: AdQuestConfig): AdQuestClient| Parameter | Type | Description |
|---|---|---|
config.apiKey required | string | Your public API key (aqk_). |
config.baseUrl required | string | The API URL, including /api/v1. Do not add /platform. |
config.externalUserId | string | Your ID for the user. You can set it later with setUser. |
config.participantToken | string | The participant token from your backend. You can set it later with setParticipantToken. |
config.previewToken | string | A Theme Studio preview token. Preview mode cannot complete quests or change rewards. |
config.locale | string | Widget language: en or fa. |
config.hostContext | Record<string, unknown> | Profile and permission context for profile quests. |
config.fetch | typeof fetch | A custom fetch, for tests or special runtimes. |
Returns: An AdQuestClient.
import { createAdQuestClient } from "@adquest/sdk";
const client = createAdQuestClient({
apiKey: "YOUR_PUBLIC_API_KEY",
baseUrl: "https://api.adquest.batriders.ir/api/v1",
externalUserId: "player-42",
participantToken: "PARTICIPANT_TOKEN",
});Set the user
Sets the user the client acts for. Most quest methods fail with an error if no user is set.
setUser(externalUserId: string): void| Parameter | Type | Description |
|---|---|---|
externalUserId required | string | Your ID for the user. |
Returns: Nothing.
Set the participant token
Replaces the participant token. Call it after you refresh the token through your backend. Pass undefined on logout.
setParticipantToken(participantToken: string | undefined): void| Parameter | Type | Description |
|---|---|---|
participantToken required | string | undefined | The new token, or undefined to clear it. |
Returns: Nothing.
client.setParticipantToken(newSession.participantToken);Set the host context
Validates and stores the host context, such as profile fields and permission states. Keep it under 8 KB.
setHostContext(context: unknown): HostContextV1| Parameter | Type | Description |
|---|---|---|
context required | unknown | A version 1 host context object. |
Returns: The normalized HostContextV1.
Returns the stored host context.
getHostContext(): HostContextV1 | nullReturns: The HostContextV1, or null if none is set.
Get the platform config
Loads your platform’s name, logo, colors, published theme and supported locales.
getPlatformConfig(): Promise<PlatformConfig>Returns: A Promise of PlatformConfig.