UNPKG

mojang

Version:

Unofficial Node.js library for Mojang's HTTP APIs

1,684 lines (764 loc) 83.6 kB
<!doctype html> <html> <head> <meta charset='utf-8' /> <title>mojang 2.0.1 | Documentation</title> <meta name='viewport' content='width=device-width,initial-scale=1'> <link href='assets/bass.css' type='text/css' rel='stylesheet' /> <link href='assets/style.css' type='text/css' rel='stylesheet' /> <link href='assets/github.css' type='text/css' rel='stylesheet' /> <link href='assets/split.css' type='text/css' rel='stylesheet' /> </head> <body class='documentation m0'> <div class='flex'> <div id='split-left' class='overflow-auto fs0 height-viewport-100'> <div class='py1 px2'> <h3 class='mb0 no-anchor'>mojang</h3> <div class='mb1'><code>2.0.1</code></div> <input placeholder='Filter' id='filter-input' class='col12 block input' type='text' /> <div id='toc'> <ul class='list-reset h5 py1-ul'> <li><a href='#mojanguser' class=""> MojangUser </a> </li> <li><a href='#mojangchallenge' class=""> MojangChallenge </a> </li> <li><a href='#mojangprofile' class=""> MojangProfile </a> </li> <li><a href='#mojangsession' class=""> MojangSession </a> </li> <li><a href='#customsession' class=""> CustomSession </a> </li> <li><a href='#status' class=""> status </a> </li> <li><a href='#getprofile' class=""> getProfile </a> </li> <li><a href='#getprofilehistory' class=""> getProfileHistory </a> </li> <li><a href='#lookupprofiles' class=""> lookupProfiles </a> </li> <li><a href='#lookupprofileat' class=""> lookupProfileAt </a> </li> <li><a href='#getordersstatistics' class=""> getOrdersStatistics </a> </li> <li><a href='#authenticate' class=""> authenticate </a> </li> <li><a href='#isvalid' class=""> isValid </a> </li> <li><a href='#refresh' class=""> refresh </a> </li> <li><a href='#invalidate' class=""> invalidate </a> </li> <li><a href='#signout' class=""> signout </a> </li> <li><a href='#issecure' class=""> isSecure </a> </li> <li><a href='#getchallenges' class=""> getChallenges </a> </li> <li><a href='#answerchallenges' class=""> answerChallenges </a> </li> <li><a href='#getsession' class=""> getSession </a> </li> <li><a href='#getblockedservers' class=""> getBlockedServers </a> </li> <li><a href='#getuser' class=""> getUser </a> </li> <li><a href='#setskin' class=""> setSkin </a> </li> <li><a href='#resetskin' class=""> resetSkin </a> </li> <li><a href='#getuserprofiles' class=""> getUserProfiles </a> </li> <li><a href='#getusercapedata' class=""> getUserCapeData </a> </li> </ul> </div> <div class='mt1 h6 quiet'> <a href='http://documentation.js.org/reading-documentation.html'>Need help reading this?</a> </div> </div> </div> <div id='split-right' class='relative overflow-auto height-viewport-100'> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='mojanguser'> MojangUser </h3> </div> <div class='pre p1 fill-light mt0'>MojangUser</div> <p> Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> </p> <div class='py1 quiet mt1 prose-big'>Properties</div> <div> <div class='space-bottom0'> <span class='code bold'>id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : user UUID </div> <div class='space-bottom0'> <span class='code bold'>email</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>firstName</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>lastName</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>username</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>registerIp</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>migratedFrom</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>migratedAt</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>registeredAt</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>passwordChangedAt</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>dateOfBirth</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>deleted</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>blocked</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>secured</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>migrated</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>emailVerified</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>legacyUser</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>verifiedByParent</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>fullName</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>fromMigratedUser</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>hashed</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> </div> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='mojangchallenge'> MojangChallenge </h3> </div> <div class='pre p1 fill-light mt0'>MojangChallenge</div> <p> Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> </p> <div class='py1 quiet mt1 prose-big'>Properties</div> <div> <div class='space-bottom0'> <span class='code bold'>answer</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code> <ul> <li><code>answer.id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> <p>used in <a href="#answerchallenges">answerChallenges</a></p> </li> </ul> </div> <div class='space-bottom0'> <span class='code bold'>question</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code> <ul> <li><code>question.id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> </li> <li><code>question.question</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a> <p>text to prompt user with</p> </li> </ul> </div> </div> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='mojangprofile'> MojangProfile </h3> </div> <div class='pre p1 fill-light mt0'>MojangProfile</div> <p> Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> </p> <div class='py1 quiet mt1 prose-big'>Properties</div> <div> <div class='space-bottom0'> <span class='code bold'>id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : profile UUID </div> <div class='space-bottom0'> <span class='code bold'>agent</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : minecraft, scrolls </div> <div class='space-bottom0'> <span class='code bold'>name</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : in-game name (IGN) </div> <div class='space-bottom0'> <span class='code bold'>userId</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : user UUID </div> <div class='space-bottom0'> <span class='code bold'>createdAt</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>legacyProfile</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>deleted</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>paid</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>migrated</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> </div> </div> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='mojangsession'> MojangSession </h3> </div> <div class='pre p1 fill-light mt0'>MojangSession</div> <p> Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> </p> <div class='py1 quiet mt1 prose-big'>Properties</div> <div> <div class='space-bottom0'> <span class='code bold'>clientToken</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>accessToken</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>selectedProfile</span> <code class='quiet'>({id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>}?)</code> </div> <div class='space-bottom0'> <span class='code bold'>availableProfiles</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;{id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>}>?)</code> </div> <div class='space-bottom0'> <span class='code bold'>user</span> <code class='quiet'>({id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>}?)</code> : always included by <a href="#authenticate">authenticate</a> </div> </div> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='customsession'> CustomSession </h3> </div> <div class='pre p1 fill-light mt0'>CustomSession</div> <p> Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> </p> <div class='py1 quiet mt1 prose-big'>Properties</div> <div> <div class='space-bottom0'> <span class='code bold'>id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : profile UUID </div> <div class='space-bottom0'> <span class='code bold'>name</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : in-game name (IGN) </div> <div class='space-bottom0'> <span class='code bold'>timestamp</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code> </div> <div class='space-bottom0'> <span class='code bold'>skin</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : URL of the current skin texture </div> <div class='space-bottom0'> <span class='code bold'>cape</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> : URL of the current cape texture </div> <div class='space-bottom0'> <span class='code bold'>isSlim</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>)</code> : true if profile is using slim model </div> </div> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='status'> status </h3> </div> <p>Returns status of various Mojang services in a more helpful format.</p> <div class='pre p1 fill-light mt0'>status(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>></div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>></code>: resolves a list like <code>[{hostname, color, isAvailable, hasIssues}]</code> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='getprofile'> getProfile </h3> </div> <p><strong>Undocumented:</strong> Gets profile data for the given profile UUID.</p> <div class='pre p1 fill-light mt0'>getProfile(profileId: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>profileId</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> profile UUID (does not work with user UUID) </div> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>></code>: resolves with <code>{id, name, legacy?, demo?}</code> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='getprofilehistory'> getProfileHistory </h3> </div> <p>Gets all name changes for a given player's profile UUID.</p> <div class='pre p1 fill-light mt0'>getProfileHistory(profileId: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;{name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, changedToAt: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>}>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>profileId</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> profile UUID (does not work with user UUID) </div> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;{name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, changedToAt: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>}>></code>: resolves if profile exists </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='lookupprofiles'> lookupProfiles </h3> </div> <p>Gets a list of abbreviated game profiles from the list of profile names.</p> <p><em>It seems results are reordered alphabetically.</em></p> <p><strong>You cannot request more than 100 names per request.</strong></p> <div class='pre p1 fill-light mt0'>lookupProfiles(names: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>>, agent: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>names</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>>)</code> list of current profile names (IGN) </div> </div> <div class='space-bottom0'> <div> <span class='code bold'>agent</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>? = <code>&#39;minecraft&#39;</code>)</code> game agent to search within (minecraft, scrolls) </div> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>></code>: resolves with <code>[{id, name, legacy?, demo?}]</code> <div class='py1 quiet mt1 prose-big'>Example</div> <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getPaidMinecraftProfiles</span> (<span class="hljs-params">names</span>) </span>{ <span class="hljs-keyword">const</span> list = <span class="hljs-keyword">await</span> getProfiles(names) <span class="hljs-keyword">return</span> list.filter(<span class="hljs-function">(<span class="hljs-params">{demo}</span>) =&gt;</span> !demo) }</pre> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='lookupprofileat'> lookupProfileAt </h3> </div> <p>Gets an abbreviated game profile at a given timestamp for an IGN name.</p> <p><strong>Prefer <a href="#lookupprofiles">lookupProfiles</a> when looking up current data.</strong></p> <div class='pre p1 fill-light mt0'>lookupProfileAt(name: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, date: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>?, agent: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>name</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code> current profile name (IGN) of the user </div> </div> <div class='space-bottom0'> <div> <span class='code bold'>date</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>?)</code> UNIX timestamp to check the username at </div> </div> <div class='space-bottom0'> <div> <span class='code bold'>agent</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>? = <code>&#39;minecraft&#39;</code>)</code> game agent to check against </div> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>></code>: resolves with <code>{id, name, legacy?, demo?}</code> <div class='py1 quiet mt1 prose-big'>Example</div> <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> {id, name, legacy, demo} = <span class="hljs-keyword">await</span> lookupProfileAt(<span class="hljs-string">'Notch'</span>, <span class="hljs-number">1503335853700</span>)</pre> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='getordersstatistics'> getOrdersStatistics </h3> </div> <p>Get statistics on the sales of Minecraft.</p> <div class='pre p1 fill-light mt0'>getOrdersStatistics(metricKeys: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>>?): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;{total: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>, last24: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>, saleVelocityPerSeconds: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>}>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>metricKeys</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>>? = <code>[&#39;item_sold_minecraft&#39;,&#39;prepaid_card_redeemed_minecraft&#39;]</code>)</code> list of metric keys to combine the stats of </div> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>&#x3C;{total: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>, last24: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>, saleVelocityPerSeconds: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>}>></code>: resolves if metricKeys is provided </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='authenticate'> authenticate </h3> </div> <p>Authenticates a user with their Mojang credentials.</p> <p><em>Use <code>agent</code> if session is for a game client, ie. a Minecraft launcher.</em></p> <p><strong>Handle access tokens securely, but they do invalidate easily. </strong></p> <div class='pre p1 fill-light mt0'>authenticate(credentials: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="#mojangsession">MojangSession</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>credentials</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code> the payload of the auth request </div> <table class='mt1 mb2 fixed-table h5 col-12'> <colgroup> <col width='30%' /> <col width='70%' /> </colgroup> <thead> <tr class='bold fill-light'> <th>Name</th> <th>Description</th> </tr> </thead> <tbody class='mt1'> <tr> <td class='break-word'><span class='code bold'>credentials.username</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>email or username of a Mojang account </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>credentials.password</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>password for the given account </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>credentials.clientToken</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>?</code> </td> <td class='break-word'><span>if empty, server will generate a client token </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>credentials.agent</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>?</code> </td> <td class='break-word'><span>if valid, adds <code>selectedProfile</code> to response </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>credentials.agent.name</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>name of the agent ('Minecraft' or 'Scrolls') </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>credentials.agent.version</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a></code> </td> <td class='break-word'><span>version number of the agent (use <code>1</code> ) </span></td> </tr> </tbody> </table> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="#mojangsession">MojangSession</a>></code>: resolves if credentials are valid <div class='py1 quiet mt1 prose-big'>Example</div> <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> clientToken = <span class="hljs-string">'loaded from settings'</span> <span class="hljs-keyword">const</span> agent = {<span class="hljs-attr">name</span>: <span class="hljs-string">'Minecraft'</span>, <span class="hljs-attr">version</span>: <span class="hljs-number">1</span>} <span class="hljs-keyword">const</span> session = <span class="hljs-keyword">await</span> mojang.authenticate({username, password, clientToken, agent}) <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'access token'</span>, session.accessToken) <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'profile id'</span>, session.selectedProfile.id) <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'minecraft ign'</span>, session.selectedProfile.name) <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'user id'</span>, session.user.id)</pre> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='isvalid'> isValid </h3> </div> <p>Checks if an access token is suitable for use with a Minecraft server.</p> <div class='pre p1 fill-light mt0'>isValid(session: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>session</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code> a session access token </div> <table class='mt1 mb2 fixed-table h5 col-12'> <colgroup> <col width='30%' /> <col width='70%' /> </colgroup> <thead> <tr class='bold fill-light'> <th>Name</th> <th>Description</th> </tr> </thead> <tbody class='mt1'> <tr> <td class='break-word'><span class='code bold'>session.accessToken</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>a session access token </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>session.clientToken</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>?</code> </td> <td class='break-word'><span>must match the one used to obtain the access token </span></td> </tr> </tbody> </table> </div> </div> <div class='py1 quiet mt1 prose-big'>Returns</div> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a>></code>: resolves true if tokens are valid <div class='py1 quiet mt1 prose-big'>Example</div> <pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">if</span> (<span class="hljs-keyword">await</span> mojang.isValid(session)) { <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'access token still good'</span>) } <span class="hljs-keyword">else</span> { <span class="hljs-built_in">console</span>.debug(<span class="hljs-string">'access token has gone bad'</span>) }</pre> </section> <section class='p2 mb2 clearfix bg-white minishadow'> <div class='clearfix'> <h3 class='fl m0' id='refresh'> refresh </h3> </div> <p>Refreshes a given access token. May work on invalid access tokens (about 1 token back in time).</p> <div class='pre p1 fill-light mt0'>refresh(session: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>&#x3C;<a href="#mojangsession">MojangSession</a>></div> <div class='py1 quiet mt1 prose-big'>Parameters</div> <div class='prose'> <div class='space-bottom0'> <div> <span class='code bold'>session</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code> a session access token </div> <table class='mt1 mb2 fixed-table h5 col-12'> <colgroup> <col width='30%' /> <col width='70%' /> </colgroup> <thead> <tr class='bold fill-light'> <th>Name</th> <th>Description</th> </tr> </thead> <tbody class='mt1'> <tr> <td class='break-word'><span class='code bold'>session.accessToken</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>a session access token </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>session.clientToken</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>?</code> </td> <td class='break-word'><span>must match the one used to obtain the access token </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>session.selectedProfile</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>?</code> </td> <td class='break-word'><span>use only with access tokens that were <strong>not</strong> assigned a game profile </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>session.selectedProfile.id</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>profile UUID </span></td> </tr> <tr> <td class='break-word'><span class='code bold'>session.selectedProfile.name</span> <code class='quiet'><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code> </td> <td class='break-word'><span>profile name (IGN) <