Skip to content

Instantly share code, notes, and snippets.

@LB-Digital
Last active July 17, 2018 14:37
Show Gist options
  • Save LB-Digital/9976daa2f88311d28b8c32a186660ba3 to your computer and use it in GitHub Desktop.
Save LB-Digital/9976daa2f88311d28b8c32a186660ba3 to your computer and use it in GitHub Desktop.
Basic usage of the Mojang API
// INFO: This script currently relies on the 'request' npm module,
// however this will change in the near future to become independant.
// http://wiki.vg/Mojang_API
const MojangAPI = {
base: "https://api.mojang.com",
getUUID: (username, done)=>{
request(MojangAPI.base + '/users/profiles/minecraft/' + username, (err, response, body)=>{
try{
var uuid = JSON.parse(body).id;
return done(null, uuid);
} catch(e){
return done(true); // err=true
}
});
},
getUsername: (uuid, done)=>{
request(MojangAPI.base + '/user/profiles/' + uuid + '/names', (err, response, body)=>{
try{
var username = JSON.parse(body).pop().name; // pop latest name change from array
return done(null, username);
} catch(e){
return done(true); // err=true
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment