The simple way is just :
const options = {};
const ank = new Ankonnect(options);
You can give options to Ankonnect
constructor, which is an object containing :
Key name | Required | Type | Default |
---|---|---|---|
userAgent | ❌ | string |
(random) |
proxy | ❌ | string | URL |
|
lang | ❌ | string |
"fr" |
baseUrl | ❌ | string |
"https://haapi.ankama.com/json/Ankama/v2" |
Once you have your constructed Ankonnect
, you have acces to :
Api
:Account
:
⚠ All async methods can throw errors, be aware to catch :
- GenericError
- GuestError
- LoginError
Create an Api key, which is the equivalent to an access token, that will be needed later to create a token to access the game.
🏳 Parameters: (CreateApiKeyRequest options
)
- options: CreateApiKeyRequest:
{
login: string;
password: string;
long_life_token: boolean;
}
⏪ Returns: CreateApiKeyResponse:
{
access: unknown[];
account_id: number;
added_date: string;
data: {
country: string;
currency: string;
};
expiration_date: string;
ip: string;
key: string;
meta: unknown[];
refresh_token: string;
}
Example:
const res = await ank.Api.createApiKey({
login: "myLogin";
password: "myPassword";
long_life_token: false;
});
console.log(res.key, res.account_id);
Create a token to access the game
🏳 Parameters: (CreateTokenRequest options
, string haapiKey
)
- options: CreateTokenRequest:
{
game: number;
}
- haapiKey: string. The key you got from createApiKey
⏪ Returns: CreateTokenResponse:
{
token: string;
}
Example:
const res = await ank.Account.createToken({
game: 18;
}, "haapiKeyFromCreateApiKey");
console.log(res.token);
Create a guest account for the game
🏳 Parameters: (CreateGuestRequest options
)
- options: CreateGuestRequest:
{
game: number;
lang: string;
captcha_token: string;
}
⏪ Returns: CreateGuestResponse:
{
added_date: string;
added_ip: string;
avatar_url: string;
birth_date: string | null;
community: string;
email: string | null;
gsm: string | null;
id: number;
lang: string;
locked: boolean;
login: string;
login_date: string | null;
login_ip: string;
nickname: string | null;
parent_email_status: string | null;
password: string;
secure: unknown;
secure_info: unknown;
security: unknown[];
type: "GUEST";
}
Example:
const res = await ank.Account.createGuest({
game: 18;
lang: "fr",
captcha_token: "getItFromACaptchaSolver"
});
console.log(res.login, res.password);
Validate a guest account
🏳 Parameters: (ValidateGuestRequest options
)
- options: ValidateGuestRequest:
{
lang: string;
guestAccountId: number;
guestLogin: string;
guestPassword: string;
login: string;
password: string;
email: string;
parentEmail: string;
birthDateTimestamp: number;
nickname: string;
}
⏪ Returns: ValidateGuestResponse:
{
_headers: {
duration: number;
}
}
Example:
const res = await ank.Account.validateGuest({
lang: "fr";
guestAccountId: 123456789;
guestLogin: "[GUEST]cceb441f";
guestPassword: "**********";
login: "myFutureLoginName";
password: "myFuturePassword";
email: "myFutureEmail";
parentEmail: "parentEmailIfNeeded";
birthDateTimestamp: 400030000;
nickname: "accountNickname";
});