title: How to retrieve the userid from userprincipalname in azure active directory?
body: <p>My client has synchronization set up between an on-premises Active Directory (AD) and Azure Active Directory (AAD).</p>
  
  <p>I am able to retrieve user information from AAD using Microsoft Graph without a problem but, I specifically need to get the <strong>AD UserID</strong>, ie ({domain}/{userid}). </p>
  
  <p>I tried calling <code>https://graph.microsoft.com/v1.0/users/firstname.lastname@domain.com/$select=userId</code> but it did not work. </p>
  
  <p>My questions are, is it possible? And in that case what is the actual attribute name? I have been looking around but haven´t been able to find a complete list of attributes.</p>
  
  <p><strong>EDIT:</strong>
  After receiving one answer from Marilee I am including the C# code I have been using, ish. Both the calls do work for receiving user information from AAD, but not the <strong>AD UserID</strong>, ie ({domain}/{userid}) that I am looking for.</p>
  
  <p>Attempt no 1</p>
  
  <pre><code>    var requestUri = GraphBaseUri + $"/v1.0/users/{upn}?$select=userId";
  
      var response = await _httpClient.GetAsync(new AuthenticationHeaderValue("Bearer", accessToken), requestUri).ConfigureAwait(false);
  
      var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
  
      dynamic responseObj = JsonConvert.DeserializeObject(content) as JObject;
  
      return responseObj.UserId; //NOT WORKING
  </code></pre>
  
  <p>Attempt no 2</p>
  
  <pre><code>    var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =&gt; {
          requestMessage
              .Headers
              .Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  
          return Task.FromResult(0);
      }));
  
      // Retrieve a user by userPrincipalName
      var user  = await graphClient
          .Users[upn]
          .Request()
          .GetAsync();
  
      return user.ObjectId; //NOT WORKING
  </code></pre>