2
votes

I want to generate an online event using Microsoft graph API.

I have office 365 subscription

I have registered an application in Azure AD with account type " Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)"

Not provided any redirect URL while configuration

I have given both delegated and application permissions for the application of Calendars.ReadWrite and have provided Admin consent.

Maven Dependencies

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>msal4j</artifactId>
        <version>1.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-nop</artifactId>
        <version>1.8.0-beta4</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.graph</groupId>
        <artifactId>microsoft-graph</artifactId>
        <version>1.7.1</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.graph</groupId>
        <artifactId>microsoft-graph-core</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.graph</groupId>
        <artifactId>microsoft-graph-auth</artifactId>
        <version>0.2.0-SNAPSHOT</version>
    </dependency>

I am using ClientCredentialProvider to create an auth provider. But whenever I am trying to create an event am getting "OrganizationFromTenantGuidNotFound"

ClientCredentialProvider authProvider =  new ClientCredentialProvider(
            CLIENT_ID,
            Arrays.asList("https://graph.microsoft.com/.default"),
            CLIENT_SECRET,
            "938db5c8-e2ce-3c76-bad7-1e00cf87b779",
            NationalCloud.Global

    );

Please find the stack trace here

stacktrace

Please help!

1
Is it correct tenant id (938db5c8-e2ce-3c76-bad7-1e00cf87b779) ?InfoÁsith
No, it's a dummy ID, but am using the correct one in the codeVarun KS

1 Answers

0
votes

UPDATE: I investigated with Varun offline. In his case, the problem was he was trying to create an event in a guest user's calendar. This was a hotmail.com user that was added to his M365 tenant as a guest. This won't work because the user's mailbox (and hence, her calendar) exists outside of the M365 tenant.

From your stack trace, you're sending your POST to https://graph.microsoft.com/v1.0/me/events. This requires a user context, since you're using the /me segment. However, from your code above, you are getting an app-only token, meaning you are authenticated as the app, not as any user. Trying to access any URL with /me will fail here.

Instead, you need to get the user's ID, then POST to https://graph.microsoft.com/v1.0/users/{user-id}/events.