title: Grant Admin Consent using Microsoft Graph API - Java
body: <p>I have created an application using graph API and I have assigned them permission - both delegated and application...</p>
  <pre><code>    ServicePrincipal servicePrincipal = graphClient.servicePrincipals(resSerPrinId)
              .buildRequest()
              .get();
      
      List&lt;AppRole&gt; appRoles = servicePrincipal.appRoles;
      List&lt;PermissionScope&gt; scopes = servicePrincipal.oauth2PermissionScopes;
      
      List&lt;ResourceAccess&gt; raList = new ArrayList&lt;ResourceAccess&gt;();
      
      for (AppRole appRole : appRoles) {
          ResourceAccess access = new ResourceAccess();
          access.id = appRole.id;
          access.type = &quot;Role&quot;;
          raList.add(access);
      }
      
      System.out.println(&quot;Roles added...&quot;);
      
      for (PermissionScope permissionScope : scopes) {
          ResourceAccess access = new ResourceAccess();
          access.id = permissionScope.id;
          access.type = &quot;Scope&quot;;
          raList.add(access);
      }
      
      System.out.println(&quot;Scopes added...&quot;);
      
      RequiredResourceAccess reqResAccess = new RequiredResourceAccess();
      reqResAccess.resourceAccess = raList;
      reqResAccess.resourceAppId = resSerPrinAppClientId;
      
      List&lt;RequiredResourceAccess&gt; rraList = new ArrayList&lt;RequiredResourceAccess&gt;();
      rraList.add(reqResAccess);
      
      Application application = graphClient.applications(clientAppObjId)
              .buildRequest()
              .get();
      
      application.requiredResourceAccess = rraList;
      
      graphClient.applications(clientAppObjId)
      .buildRequest()
      .patch(application);
  </code></pre>
  <p>Here in the code above, <strong>resSerPrinId</strong> is resource service principal Id which has app roles in manifest and a scope in &quot;expose an api&quot; section...</p>
  <p>So I am pulling out appRoles and oauth2Permission from that resource service principal and sending them to client service principal...</p>
  <p>In the UI I am seeing that the permissions do not have grant...</p>
  <p><a href="https://i.stack.imgur.com/m5rP2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m5rP2.png" alt="enter image description here" /></a></p>
  <p>Is it possible to give them admin grant using some graph API or or manually loading these permission and then giving them admin grant...or do I need to always use the UI to do it...?</p>