Java Code to write several Events in Teams's Calendar

Ismael 0 Reputation points
2025-03-20T18:00:29.1433333+00:00

Hi,

I am trying to save some Events in Teams Calendar with Microsoft Graph API via batch request, but I think I am not doing correctly. I cannot find examples.

First I initialise the service client this way:

ClientSecretCredential credential = new ClientSecretCredentialBuilder()
        .clientId(clientId)
        .clientSecret("my_secret")
        .tenantId(tenantId)
        .build();

GraphServiceClient graphClient = new GraphServiceClient(credential, graphUserScopes.toArray(new String[0]))

Then I try to execute the following code:

BatchRequestContent batchRequestContent = new BatchRequestContent(graphClient);
Map<String, ParsableFactory<? extends Parsable>> errorMappings = new HashMap<>();

int requestId = 1;
String clientId = user.email;

MyOwnEventsClassList.each {
    com.microsoft.graph.models.Event microsoftEvent = createCalendarTeamsEvent(user, it);
    RequestInformation eventRequestInformation = graphClient.users()
            .byUserId(teacherTeamsUserId)
            .events()
            .toPostRequestInformation(microsoftEvent);

    BatchRequestStep batchRequestStep = new BatchRequestStep(String.valueOf(requestId), eventRequestInformation);
    batchRequestContent.addBatchRequestStep(batchRequestStep)
    requestId++;
}

// Enviar batch request a Graph API
BatchResponseContent batchResponseContent = graphClient.getBatchRequestBuilder().post(batchRequestContent, errorMappings);

It seems that the method toPostRequestInformation is not the right one to create a request that new BatchRequestStep can accept.
This is the error I got.
Could not find matching constructor for: com.microsoft.graph.core.models.BatchRequestStep(String, com.microsoft.kiota.RequestInformation)

Could someone help me, how is the right way to proceed with this?

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.