title: Azure AD: Grant an appRoleAssignment for a service principal is failing with "code": "Request_ResourceNotFound"
body: <p>I am trying to create a &quot;service principal&quot; for application and to grant admin consent for the permissions using Microsoft graph API.</p>
  <p>I followed the following steps:</p>
  <ol>
  <li><p>Created application in a tenant using graph API. My request body is:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;displayName&quot;: &quot;AppWithPermissions&quot;,
    &quot;requiredResourceAccess&quot;: [
      {
        &quot;resourceAppId&quot;: &quot;00000002-0000-0ff1-ce00-000000000000&quot;,
        &quot;resourceAccess&quot;: [
          {
            &quot;id&quot;: &quot;dc890d15-9560-4a4c-9b7f-a736ec74ec40&quot;,
            &quot;type&quot;: &quot;Role&quot;
          }
        ]
      }
    ]
  }
  </code></pre>
  </li>
  <li><p>Created a service principal for the above-created application. The creation was successful.</p>
  </li>
  <li><p>Now, I want to grant admin consent to each assigned permission programmatically using graph API.</p>
  </li>
  <li><p>To grant application permissions, I created an app role assignment in the appRoleAssignedTo collection of the API's service principal:
  The request was as follows:</p>
  <p>Post request:</p>
  <pre class="lang-none prettyprint-override"><code>https://graph.microsoft.com/v1.0/servicePrincipals/{id}/appRoleAssignedTo
  </code></pre>
  <p>Request body:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;principalId&quot;: &quot;principal_id&quot;,
      &quot;resourceId&quot;: &quot;resource_id&quot;,
      &quot;appRoleId&quot;: &quot;approle_id&quot;
  }
  </code></pre>
  </li>
  </ol>
  <p>Here,</p>
  <ol>
  <li>&quot;principal_id&quot; is the &quot;id&quot; of service principal created in step 2 above.</li>
  <li>&quot;approle_id&quot; is the id of the appRole you want to grant. (taken &quot;id&quot; value from &quot;resourceAccess&quot; array present in &quot;requiredResourceAccess&quot;)</li>
  <li>&quot;id&quot; in http request url and &quot;resource_id&quot; are the same. (taken &quot;resourceAppId&quot; value from &quot;requiredResourceAccess&quot; which is corresponds to &quot;approle_id&quot; given above)</li>
  </ol>
  <p>After running the query, I am getting error 404.
  &quot;code&quot;: &quot;Request_ResourceNotFound&quot;
  for the &quot;resource_id&quot;/&quot;id&quot; field.</p>
  <ul>
  <li>Adding screenshots for better understandings:</li>
  </ul>
  <ol>
  <li>App Creation:</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/3r11N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3r11N.png" alt="enter image description here" /></a></p>
  <ol start="2">
  <li>service principal creation:</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/yF8cu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yF8cu.png" alt="enter image description here" /></a></p>
  <ol start="3">
  <li>Grant an appRoleAssignment for a service principal:</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/nnusU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nnusU.png" alt="enter image description here" /></a></p>
  <p>I am confused about which IDs to use where and didn't get a clear idea from the documentations. Can any one please resolve my query? Thanks in advance.</p>