javaazuremicrosoft-graph-api

Java - ODataError "The mailbox is either inactive, soft-deleted, or is hosted on-premise."


I am trying to create calendar events using graph api. But on call i am getting response with an error: com.microsoft.graph.models.odataerrors.ODataError: The mailbox is either inactive, soft-deleted, or is hosted on-premise.

    private String postCalendarEventForClients(Event event, TeamsCalendarCreateRequestDTO requestDTO) {
    String caluid = requestDTO.getICalUId() == null ? "NaN" : requestDTO.getICalUId();
    UserCollectionResponse usrs = graphClient.users().get();
    for (User usr : usrs.getValue()) {
    }
    for (String clientEmail : requestDTO.getClientEmails()) {
        Event createdEvent = graphClient.users().byUserId(user.getMail()).events().post(event);
    }
    return caluid;
}


@Bean
public GraphServiceClient graphServiceClient() {
    // Create an authentication provider for Microsoft Graph API
    final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
            .clientId(clientId).tenantId(tenantId).clientSecret(clientSecret).build();

    // Initialize and return Graph client
    return new GraphServiceClient(credential, scopes.toArray(new String[0]));
}

These are my app permissions

enter image description here

The user has assigned Office 365 Standard license in through Microsoft Admin Console. I can manually access the calendar and create events there. But the license does not appear in Azure->User->Licenses enter image description here enter image description here

License assigned in Microsoft 365 Admin Console enter image description here


Solution

  • The error occurs if the user is guest or external user without any license in current tenant and have active M365 license assigned in main tenant.

    I have one guest user without any license in current tenant but having active M365 license assigned in main tenant as below:

    Current tenant:

    enter image description here

    Main tenant:

    enter image description here

    Based on below UPN, Patrik is guest or external user in company0 workspace whereas local user with active M365 license in companydisk workspace.

    patrik.surname_companydisk.onmicrosoft.com#EXT#@company0.onmicrosoft.com
    

    To resolve the error, switch to companydisk directory and register one new application in it and user that app's client ID and client secret for authentication purpose.