Skip to content

Documentation


Documentation / @blizzard-api/client / BlizzardApiClient

Class: BlizzardApiClient ​

Defined in: client/src/client/client.ts:44

A Blizzard API client.

Example ​

ts
const client = new BlizzardApiClient({
 key: 'client',
 secret: 'secret',
 origin: 'eu',
 locale: 'en_GB',
 token: 'access'
});

Constructors ​

Constructor ​

new BlizzardApiClient(options): BlizzardApiClient

Defined in: client/src/client/client.ts:61

Parameters ​

options ​

ClientOptions

Returns ​

BlizzardApiClient

Properties ​

defaults ​

defaults: object

Defined in: client/src/client/client.ts:45

key ​

key: string

locale ​

locale: Locales

maxAttempts ​

maxAttempts: number

origin ​

origin: Origins

retryOnRateLimit ​

retryOnRateLimit: boolean

secret ​

secret: string

token? ​

optional token?: string

Methods ​

cancelTokenRefresh() ​

cancelTokenRefresh(): void

Defined in: client/src/client/client.ts:86

Cancel the automatic token refresh scheduled by createBlizzardApiClient.

Returns ​

void


getAccessToken() ​

getAccessToken(options?): Promise<AccessToken>

Defined in: client/src/client/client.ts:103

Get an access token.

Parameters ​

options? ​

AccessTokenRequestArguments

The access token request arguments. See AccessTokenRequestArguments.

Returns ​

Promise<AccessToken>

The access token. See AccessToken.

Example ​

ts
const response = await client.getAccessToken();
const { access_token, token_type, expires_in, sub } = response;
console.log(access_token, token_type, expires_in, sub);
// => 'access'
// => 'bearer'
// => 86399
// => 'client-id'

getRequestConfig() ​

getRequestConfig<T, Protected>(resource, options?): object

Defined in: client/src/client/client.ts:126

Get the request configuration.

Type Parameters ​

T ​

T

Protected ​

Protected extends boolean = false

Parameters ​

resource ​

Resource<T, object, Protected>

The resource to fetch. See Resource.

options? ​

Partial<ClientOptions>

Client options. See ClientOptions.

Returns ​

object

The request configuration.

headers ​

headers: Record<string, string> & object

Type Declaration ​
Authorization ​

Authorization: `Bearer ${string}`

Battlenet-Namespace? ​

optional Battlenet-Namespace?: string

Content-Type ​

Content-Type: "application/json"

searchParams ​

searchParams: Record<string, unknown> & object

Type Declaration ​
locale ​

locale: "de_DE" | "en_GB" | "en_US" | "es_ES" | "es_MX" | "fr_FR" | "it_IT" | "ko_KR" | "pt_BR" | "ru_RU" | "zh_CN" | "zh_TW"


getRequestUrl() ​

getRequestUrl<T, Protected>(resource, options?): string

Defined in: client/src/client/client.ts:180

Get the request URL.

Type Parameters ​

T ​

T

Protected ​

Protected extends boolean = false

Parameters ​

resource ​

Resource<T, object, Protected>

The resource to fetch. See Resource.

options? ​

Partial<ClientOptions>

Client options. See ClientOptions.

Returns ​

string

The request URL.


refreshAccessToken() ​

refreshAccessToken(options?): Promise<AccessToken>

Defined in: client/src/client/client.ts:205

Refresh the access token.

Parameters ​

options? ​

AccessTokenRequestArguments

The access token request arguments. See AccessTokenRequestArguments.

Returns ​

Promise<AccessToken>

The access token. See AccessToken.

Example ​

ts
const response = await client.refreshAccessToken();
const { access_token, token_type, expires_in, sub } = response;
console.log(access_token, token_type, expires_in, sub);
// => 'access'
// => 'bearer'
// => 86399
// => 'client-id'

sendRequest() ​

sendRequest<T, Protected>(resource, options?): Promise<T | undefined>

Defined in: client/src/client/client.ts:217

Send a request to the Blizzard API.

Type Parameters ​

T ​

T

Protected ​

Protected extends boolean = false

Parameters ​

resource ​

Resource<T, object, Protected>

The resource to fetch. See Resource.

options? ​

Partial<ClientOptions>

Client options. See ClientOptions.

Returns ​

Promise<T | undefined>

The response from the Blizzard API.


setAccessToken() ​

setAccessToken(token): void

Defined in: client/src/client/client.ts:262

Set the access token.

Parameters ​

token ​

string

The access token.

Returns ​

void


validateAccessToken() ​

validateAccessToken(options?): Promise<ValidateAccessTokenResponse>

Defined in: client/src/client/client.ts:275

Validate an access token.

Parameters ​

options? ​

ValidateAccessTokenArguments

The validate access token arguments. See ValidateAccessTokenArguments.

Returns ​

Promise<ValidateAccessTokenResponse>

The response from the Blizzard API. See ValidateAccessTokenResponse.

Example ​

ts
const response = await client.validateAccessToken({ token: 'access' });
console.log(response.client_id);
// => 'client-id'

withUserToken() ​

withUserToken(token): BlizzardApiClient

Defined in: client/src/client/client.ts:297

Create a client that uses a user access token for requests without changing this client's token.

Parameters ​

token ​

string

The user access token, typically acquired through Blizzard's authorization code flow.

Returns ​

BlizzardApiClient

A client scoped to the supplied user token.