Skip to documentation
AdQuestDocs

Client

Create the typed AdQuest client and set the user, token and host context.

On this page

Install

Terminal
npm install @adquest/sdk

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

Signature
function createAdQuestClient(config: AdQuestConfig): AdQuestClient
ParameterTypeDescription
config.apiKey requiredstringYour public API key (aqk_).
config.baseUrl requiredstringThe API URL, including /api/v1. Do not add /platform.
config.externalUserIdstringYour ID for the user. You can set it later with setUser.
config.participantTokenstringThe participant token from your backend. You can set it later with setParticipantToken.
config.previewTokenstringA Theme Studio preview token. Preview mode cannot complete quests or change rewards.
config.localestringWidget language: en or fa.
config.hostContextRecord<string, unknown>Profile and permission context for profile quests.
config.fetchtypeof fetchA custom fetch, for tests or special runtimes.

Returns: An AdQuestClient.

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

Signature
setUser(externalUserId: string): void
ParameterTypeDescription
externalUserId requiredstringYour 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.

Signature
setParticipantToken(participantToken: string | undefined): void
ParameterTypeDescription
participantToken requiredstring | undefinedThe new token, or undefined to clear it.

Returns: Nothing.

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

Signature
setHostContext(context: unknown): HostContextV1
ParameterTypeDescription
context requiredunknownA version 1 host context object.

Returns: The normalized HostContextV1.

Returns the stored host context.

Signature
getHostContext(): HostContextV1 | null

Returns: The HostContextV1, or null if none is set.

Get the platform config

Loads your platform’s name, logo, colors, published theme and supported locales.

Signature
getPlatformConfig(): Promise<PlatformConfig>

Returns: A Promise of PlatformConfig.

Next

Something unclear, missing or wrong here? Tell us