wrapper-mojang-api is a simple JavaScript wrapper for the Mojang API. The package is divided into 2 submodules: Yggdrasil for authentication, and Mojang for requests to the Mojang API. All requests are done asynchronously using the axios package.
npm install --save wrapper-mojang-api
This example shows how you can change an accounts username using wrapper-mojang-api
const { Yggdrasil, Mojang } = require("wrapper-mojang-api");
const email = "user@domain.net";
const password = "password";
const questions = ["answer", "answer", "answer"];
const newName = "newname";
const main = async () => {
const { accessToken, selectedProfile } = await Yggdrasil.authenticate(email, password);
if (await Mojang.needSecurity(accessToken)) await Mojang.answerSecurity(accessToken, questions);
try {
await Mojang.changeName(selectedProfile.id, password, newName, accessToken);
console.log("Name changed to "+ newName);
} catch (err) {
console.log("Name change failed. Error code "+err.response.status);
}
}
main();
Authenticates your account, gives you accessToken.
Parameters:
-
email
- email of the account -
password
- password of the account -
requestUser
- optional parameter which defaults to false. Adds user object with aditional information to the response
Response:
{
"accessToken": "",
"clientToken": "",
"availableProfiles": [ { "name": "", "id": "" } ],
"selectedProfile": { "name": "", "id": "" }
}
Checks if your accessToken is still valid.
Parameters:
-
token
- access token obtained through authentication
Response:
-
true
orfalse
Returns status of various Mojang services. Possible values are green (no issues), yellow (some issues), red (service unavailable).
Response:
[
{ "minecraft.net": "green" },
{ "session.minecraft.net": "green" },
{ "account.mojang.com": "green" },
{ "authserver.mojang.com": "green" },
{ "sessionserver.mojang.com": "red" },
{ "api.mojang.com": "green" },
{ "textures.minecraft.net": "green" },
{ "mojang.com": "green" }
]
Returns a list of corresponding uuids to a list of given names
Parameters:
-
names
- Either a username or an array of usernames
Response:
[
{
"id": "0d252b7218b648bfb86c2ae476954d32",
"name": "maksimkurb",
"legacy": true,
"demo": true
}
]
-
legacy
(unmigrated) anddemo
(unpaid) only appear when true
Returns the uuid of the account which had the specified username at the specified time
Parameters:
-
username
- Minecraft username -
time
- Date object or unix timestamp (time in seconds since 1-1-1970). Or if it is 0 it will return the original name's owner given that the name was changed.
Response:
{
"id": "7125ba8b1c864508b92bb5c042ccfe2b",
"name": "KrisJelbring"
}
Returns history of usernames of an account
Parameters:
-
uuid
- uuid of account
Response:
[
{
"name": "Gold"
},
{
"name": "Diamond",
"changedToAt": 1414059749000
}
]
This returns the profile of the requested user (username, skin, cape...). You can only request the same profile 1 time a minute.
Parameters:
-
uuid
- uuid of account
Response:
{
"id": "<profile identifier>",
"name": "<player name>",
"properties": [
{
"name": "textures",
"value": "<base64 string>",
}
]
}
This changes the name of the given account
Parameters:
-
uuid
- the uuid of account -
password
the password of account -
name
- the desired name -
token
- access token obtained through authentication
Response:
-
204
- Success -
400
- Name is unavailable -
401
- Unauthorized -
403
- Forbidden -
504
- Timed out
Reserve name for an account for 24 hours. Also known as blocking
Parameters:
-
name
- the desired name -
token
- access token obtained through authentication
Response:
-
204
- Success -
400
- Name is unavailable -
401
- Unauthorized -
403
- Forbidden -
504
- Timed out
Returns whether or not you need to answer security questions for this ip address.
Parameters:
-
token
- access token obtained through authentication
Response:
-
true
orfalse
Returns your security questions and the answer id's that need to be sent along with the answers
Parameters:
-
token
- access token obtained through authentication
Response:
[
{
"answer": {"id": 123},
"question": {
"id": 1,
"question": "What is your favorite pet's name?"
}
},
{
"answer": {"id": 456},
"question": {
"id": 2,
"question": "What is your favorite movie?"
}
},
{
"answer": {"id": 789},
"question": {
"id": 3,
"question": "What is your favorite author's last name?"
}
}
]
Answers your security questions. If you do not have any (SFA alt) it skips
Parameters:
-
token
- access token obtained through authentication -
questions
- an array containing the 3 answers to your security questions
- Discens - Main developer
wrapper-mojang-api is licensed under the MIT license.