title: Microsoft Graph API - Create user in Azure AD B2C with local account identity gives Request_ResourceNotFound error
body: <p>My goal is to create a local account, like <code>michele@gmail.com</code>, in <strong>Azure Active Directory B2C</strong>. </p>
  
  <p>I want to use my own UI, so I started to look at how to implement the API. After some research, it looks like the best way to do it should be via Microsoft Graph.</p>
  
  <p>I started by following <a href="https://docs.microsoft.com/en-us/azure/active-directory-b2c/manage-user-accounts-graph-api" rel="nofollow noreferrer">Manage Azure AD B2C user accounts with Microsoft Graph</a>, and I properly created an app (not sure if I need to choose the third options, but looks like the broader one):</p>
  
  <p><a href="https://i.stack.imgur.com/B5Vid.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B5Vid.png" alt="enter image description here"></a></p>
  
  <p>with the following permissions (updated following also @Tony Ju screenshot):</p>
  
  <p><a href="https://i.stack.imgur.com/ehSnG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ehSnG.png" alt="enter image description here"></a></p>
  
  <p>Then I created the client secret and coded my own <a href="https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/CustomAuthenticationProvider.md" rel="nofollow noreferrer">auth provider</a></p>
  
  <pre class="lang-js prettyprint-override"><code>const { AuthenticationContext } = require('adal-node');
  
  class AuthProvider {
  
      async getAccessToken() {
          return new Promise((resolve, reject) =&gt; {
              const tenant = 'tenant';
              const authority = `https://login.microsoftonline.com/${tenant}`;
  
              const authenticationContext = new AuthenticationContext(authority);
  
              const resource = 'https://graph.microsoft.com';
              const clientId = 'clientId';
              const clientSecret = 'clientSecret';
  
              authenticationContext.acquireTokenWithClientCredentials(
                  resource,
                  clientId,
                  clientSecret,
                  (err, tokenResponse) =&gt; {
                      if (err) {
                          console.error('error!', err);
                          return reject(err);
                      }
                      return resolve(tokenResponse.accessToken);
                  },
              );
          });
      }
  }
  </code></pre>
  
  <p>and initialized the client</p>
  
  <pre class="lang-js prettyprint-override"><code>require('isomorphic-fetch'); //needed for server side request with the client
  const { Client } = require('@microsoft/microsoft-graph-client');
  
  const options = {
      authProvider: new AuthProvider(),
  };
  const client = Client.initWithMiddleware(options);
  </code></pre>
  
  <p><a href="https://docs.microsoft.com/en-gb/graph/api/user-post-users?view=graph-rest-1.0&amp;tabs=http#example-2-create-a-user-with-social-and-local-account-identities" rel="nofollow noreferrer">Following the official documentation</a>, I create a local account</p>
  
  <pre class="lang-js prettyprint-override"><code>const user = {
      displayName: 'John Smith',
      identities: [
          {
              signInType: 'emailAddress',
              issuer: 'MY_ISSUER.onmicrosoft.com',
              issuerAssignedId: 'jsmith@yahoo.com',
          },
      ],
      passwordProfile: {
          password: 'df42bfe2-8060-411f-b277-06b819874573',
      },
      passwordPolicies: 'DisablePasswordExpiration',
  };
  
  client
      .api('/users')
      .post(user)
      .then(data =&gt; console.log(data))
      .catch(e =&gt; console.error(e))
  </code></pre>
  
  <p>And I get back this "Request_ResourceNotFound" error</p>
  
  <pre class="lang-js prettyprint-override"><code>GraphError {
    statusCode: 404,
    code: 'Request_ResourceNotFound',
    message:
     'Resource \'User_30140fa1-ae7e-40b7-ad5a-ef4d0b4cd4dc\' does not exist or one of its queried reference-property objects are not present.',
    requestId: 'fbf4c987-0383-472a-bc22-c94f98710344',
    date: 2020-05-18T13:19:14.000Z,
    body:
     '{"code":"Request_ResourceNotFound","message":"Resource \'User_30140fa1-ae7e-40b7-ad5a-ef4d0b4cd4dc\' does not exist or one of its queried reference-property objects are not present.","innerError":{"request-id":"fbf4c987-0383-472a-bc22-c94f98710344","date":"2020-05-18T15:19:14"}}' }
  </code></pre>
  
  <p>The error does not help and I don't know how to continue. The basic configuration looks correct, because I'm able to get all the users and also <a href="https://docs.microsoft.com/en-gb/graph/api/user-post-users?view=graph-rest-1.0&amp;tabs=http#example-1-create-a-user" rel="nofollow noreferrer">create a user in the same tenant</a>. </p>
  
  <p>What am I missing? Feels so weird having this type of error by following the official docs. I'm starting to think that I need to use the invitation API, but I just want to create a user and don't go into the full email verification flow. Plus, what I exactly need is in the official docs and I would expect it to work. So maybe there is just something wrong on my side.</p>