Trying to call graph calendar API using ClientSecret flow from java code but I am getting url not found error from code.
Below is the code being used - the same ClientSecret flow works for getting the AD details of user.
public class ClientSecretFlow {
private final static List<String> SCOPES = Arrays.asList("https://graph.microsoft.com/.default");
public static void main(String[] args) throws Exception {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("81df77....").clientSecret("BHf7Q.....")
.tenantId("c4714741....").build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(SCOPES,
clientSecretCredential);
final OkHttpClient httpClient = HttpClients.createDefault(tokenCredentialAuthProvider);
String json = "{\"subject\": \"Event testing\",\"start\": {\"dateTime\": \"2021-12-15T08:34:45.317Z\",\"timeZone\": \"UTC\"},\"end\": { \"dateTime\": \"2021-12-20T08:34:45.317Z\", \"timeZone\": \"UTC\"}}";
RequestBody formBody = RequestBody.create(MediaType.parse("application/json"), json);
Request calendarrequest = new Request.Builder()
.url("https://graph.microsoft.com/v1.0/users/{userid}/calendar/events").post(formBody)
.build();
try {
Response response = httpClient.newCall(calendarrequest).execute();
System.out.println(response);
// Do something with the response.
} catch (IOException e) {
e.printStackTrace();
}
// sending outlook mails for calendar invite
}
}