title: yammer get user token yammer REST API
body: <p>I'm trying to add user to Yammer group, For this I need to have the token of the user whom I want to add to the group. I've used the following endpoint to access the user token</p>
  
  <pre><code>https://api.yammer.com/api/v1/oauth/tokens.json?user_id={0}&amp;consumer_key={1}
  </code></pre>
  
  <p>For consumer_key I'm passing the ClientID of the yammer application that I've created (using Verified admin account).</p>
  
  <p>The problem is that for some user the endpoint is working fine and returning me the JSON response. But for some user the endpoint is returning "<strong>The remote server returned an error: (400) Bad Request.</strong>"</p>
  
  <p>Please, find my code below</p>
  
  <pre><code>private YammerJSONUserContract GetUserDetailsFromYammer(string userID, string clientID)
      {
          YammerJSONUserContract objUser = null;
          try
          {
              string URL = string.Format(this.userImpersonationURL, userID, clientID);
              string jsonString = PostYammerJson(URL, this._adminAccessToken, "GET");
              YammerJSONUserContract [] objUserCollection = Newtonsoft.Json.JsonConvert.DeserializeObject&lt;YammerJSONUserContract[]&gt;(jsonString);
              objUser = objUserCollection[0];
          }
          catch (Exception ex)
          {
              throw ex;
          }
          return objUser;
      }
  private string PostYammerJson(string url, string accessToken, string httpMethod)
      {
          string json = string.Empty;
          try
          {
  
              HttpWebRequest YammerRequest = HttpWebRequest.Create(url) as HttpWebRequest;
              YammerRequest.Method = httpMethod;
              YammerRequest.ContentType = "application/json; odata=verbose";
              YammerRequest.Accept = "application/json; odata=verbose";
              YammerRequest.ContentLength = 0;
              YammerRequest.Headers.Add("Authorization", string.Concat("Bearer ", accessToken));
              using (HttpWebResponse response = YammerRequest.GetResponse() as HttpWebResponse)
              {
                  Encoding encode = Encoding.GetEncoding("utf-8");
                  StreamReader reader = new StreamReader(response.GetResponseStream(), encode);
                  json = reader.ReadToEnd();
              }
          }
          catch (Exception ex)
          {
              throw ex;
          }
          return json;
      }
  </code></pre>
  
  <p>Can someone please let me know what I'm missing and why the API returning the user details for some users but not all.</p>
  
  <p>Waiting for your response.</p>
  
  <p>Cheers 
  Amlan </p>