Can we create OneDrive User(s) with OneDrive license using Microsoft Graph API?

Viewed 35

I am trying to create User(s) using Microsoft Graph API. Here is the code snippet.

    User user = new User();
    user.accountEnabled = true;
    user.displayName = "xyz abc";
    user.mailNickname = "xyz";
    user.userPrincipalName = "abc.xyz@domain.onmicrosoft.com";
    PasswordProfile passwordProfile = new PasswordProfile();
    passwordProfile.forceChangePasswordNextSignIn = true;
    passwordProfile.password = "xWwvJ]6NMw+bWH-d";
    user.passwordProfile = passwordProfile;

    graphClient.users()
            .buildRequest()
            .post(user);

but when I trying to list Drive(s) with respect to newly created user, then it saying "Not Found".

DriveCollectionPage drives = graphClient.users("8edd0021-c931-4df0-a062-a42ff3aee845").drives()
            .buildRequest()
            .get();

Microsoft documentation says:

OneDrive users will always have at least one drive available, their default drive. Users without a OneDrive license may not have a default drive available.

So it means the user which I have created is not a OneDrive User because it does have OneDrive license with it, therefore, I have following questions

  1. Can we create OneDrive User with OneDrive license?

  2. Can all user(s) have same OneDrive license or each user requires a different OneDrive license? When I am trying to add license of an existing OneDrive User to a new user it's saying Bad Request

            if(user.id.equals("8edd0021-c931-4df0-a062-a42ff3aee845")){
            LinkedList<AssignedLicense> addLicensesList = new LinkedList<AssignedLicense>();
            AssignedLicense addLicenses = new AssignedLicense();
            addLicenses.skuId = UUID.fromString("zadc11ab-d86c-5c30-b9a4-bada4kdc1dbc");
            addLicensesList.add(addLicenses);
            AssignedLicense anotherLicenses = new AssignedLicense();
            anotherLicenses.skuId = UUID.fromString("a4132ec9-19d9-944c-o51c-d6b45b384dbbc");
            addLicensesList.add(anotherLicenses);
            graphClient.users("8edd0021-c931-4df0-a062-a42ff3aee845").assignLicense(UserAssignLicenseParameterSet.newBuilder()
                    .withAddLicenses(addLicensesList)
                    .withRemoveLicenses(Collections.emptyList()).build()
            ).buildRequest().post();
        }
    
0 Answers
Related