title: Error 400 - Bad Request an Creating user with Microsoft Graph
body: <p>I am trying to create a new user in my tenant using Microsoft Graph (v1.0) with help of the Microsoft doc.<br>
  When I create my user, I always get an <code>error 400 bad request</code> as response.</p>
  
  <p>I am using HttpClient to make the post Request.</p>
  
  <p>My Function :</p>
  
  <pre><code>private async Task&lt;string&gt; BuildUser(string token, string query)
      {
          httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
          UserCreation uc = new UserCreation
          {
              accountEnabled = this.checkBoxActive.Checked,
              displayName = this.textBoxDN.Text,
              mailNickName = this.textBoxMail.Text,
              passwordProfile = new PasswordProfile { forceChangePasswordNextSignIn = this.checkBoxChangeMDP.Checked, password = this.textBoxPassword.Text},
              userPrincipalName = this.textBoxUPN.Text
          };
  
          string json = JsonConvert.SerializeObject(uc);
          var content = new StringContent(json, Encoding.UTF8, "application/json");
          HttpResponseMessage response = httpClient.PostAsync(query, content).Result;
          return response.ToString();
      }
  </code></pre>
  
  <p>My token is valid and i am able to make simple Get requests, my app have the authorizations  mentioned <a href="https://docs.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0" rel="nofollow noreferrer">here</a>.</p>
  
  <p>For example, my json var can contains :</p>
  
  <pre><code>{
      "accountEnabled":true,
      "displayName":"cyril testgraphh",
      "mailNickName":"cyriltestgraphh",
      "userPrincipalName":"cyriltestgraphh@mytenant.fr",
      "passwordProfile":{
          "forceChangePasswordNextSignIn":true,
          "password":"XXX"
      }
  }
  </code></pre>
  
  <p>EDIT :
  I solved my problem by using Microsoft Graph objects (Microsoft.Graph.User and Microsoft.Graph.PasswordProfile) and add .onmicrosoft.com to my upn</p>