title: Mojang API - Retrieve latest UUID of username
body: <p>I am currently trying to make an API call using cURL with PHP to retrieve the UUID of the <strong>latest</strong> user that has used a username.</p>
  
  <p>Using the <a href="http://wiki.vg/Mojang_API" rel="nofollow">Mojang API</a>:</p>
  
  <blockquote>
    <p>Username -> UUID at time</p>
  </blockquote>
  
  <p>When making an API call for example: the user '<em>Chocolates</em>' (Which has been used by four users according to <a href="https://namemc.com/s?Chocolates" rel="nofollow">NameMC</a>) I get the UUID of the first ever user using that name.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>public function api_Changedto($uuid, $username)
     {
        $ch = curl_init();
  
        //Set other default cUrl settings
        curl_setopt(        $ch, CURLOPT_FOLLOWLOCATION,   1);
        curl_setopt(        $ch, CURLOPT_HEADER,           0);
        curl_setopt(        $ch, CURLOPT_RETURNTRANSFER,   1);
        curl_setopt(        $ch, CURLOPT_POST,         0);
        curl_setopt(        $ch, CURLOPT_URL,          "https://api.mojang.com/user/profiles/" . $uuid . "/names");
  
        curl_setopt(        $ch, CURLOPT_CAINFO,     "certificates/curl/cacert.pem");
  
        $response = curl_exec($ch);
  
        if($response) {
           $decoded = json_decode($response);
  
           $match = false;
  
           foreach ($decoded as $userInfo){
  
              if($match){
  
                 $changedTo = ($userInfo-&gt;changedToAt + 3196800000) / 1000; 
                 break;
  
              }else{
                 if(strtolower($username) == strtolower($userInfo-&gt;name)){
                    $match = true;
                 }
              }
           }
        }
        return $changedTo;
     }
  </code></pre>
  
  <blockquote>
    <p>?at=0 can be used to get the UUID of the original user of that
    username</p>
  </blockquote>
  
  <p>Is there a workaround to achieve this?</p>
  
  <p>Thanks in advance,</p>