# Client

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

Source: https://dashboard.adquest.batriders.ir/docs/sdk/client · Audience: Developers · Section: SDK reference

## Install

**Terminal**

```bash
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

### `createAdQuestClient`

Creates a client for one platform. Call setUser and setParticipantToken when the signed-in user changes.

```typescript
function createAdQuestClient(config: AdQuestConfig): AdQuestClient
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| config.apiKey | string | yes | Your public API key (aqk_). |
| config.baseUrl | string | yes | The API URL, including /api/v1. Do not add /platform. |
| config.externalUserId | string | no | Your ID for the user. You can set it later with setUser. |
| config.participantToken | string | no | The participant token from your backend. You can set it later with setParticipantToken. |
| config.previewToken | string | no | A Theme Studio preview token. Preview mode cannot complete quests or change rewards. |
| config.locale | string | no | Widget language: en or fa. |
| config.hostContext | Record<string, unknown> | no | Profile and permission context for profile quests. |
| config.fetch | typeof fetch | no | A custom fetch, for tests or special runtimes. |

**Returns:** An AdQuestClient.

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

### `setUser`

Sets the user the client acts for. Most quest methods fail with an error if no user is set.

```typescript
setUser(externalUserId: string): void
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| externalUserId | string | yes | Your ID for the user. |

**Returns:** Nothing.

## Set the participant token

### `setParticipantToken`

Replaces the participant token. Call it after you refresh the token through your backend. Pass undefined on logout.

```typescript
setParticipantToken(participantToken: string | undefined): void
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| participantToken | string \| undefined | yes | The new token, or undefined to clear it. |

**Returns:** Nothing.

```typescript
client.setParticipantToken(newSession.participantToken);
```

## Set the host context

### `setHostContext`

Validates and stores the host context, such as profile fields and permission states. Keep it under 8 KB.

```typescript
setHostContext(context: unknown): HostContextV1
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| context | unknown | yes | A version 1 host context object. |

**Returns:** The normalized HostContextV1.

### `getHostContext`

Returns the stored host context.

```typescript
getHostContext(): HostContextV1 | null
```

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

## Get the platform config

### `getPlatformConfig`

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

```typescript
getPlatformConfig(): Promise<PlatformConfig>
```

**Returns:** A Promise of PlatformConfig.

## Next

- [Quests](https://dashboard.adquest.batriders.ir/docs/sdk/quests): List, start and complete quests.
- [Rewards](https://dashboard.adquest.batriders.ir/docs/sdk/rewards): Balance, lotteries and claims.
- [Errors](https://dashboard.adquest.batriders.ir/docs/sdk/errors): AdQuestError and its codes.
