How to create an online event with GraphAPI?

Dilara Ünal 0 Reputation points
2024-06-25T13:59:56.4933333+00:00

Hi,

I'm following https://learn.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http these steps. But i can't create online event. I always create normal event. My account is work account. I added screenshot for my scopes. Also here is my code snippet:

public ResponseEntity<String> createMicrosoftEvent(String microsoftAccessToken, MicrosoftEventDto microsoftEventDto) {
    String url = "https://graph.microsoft.com/v1.0/me/events";
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setBearerAuth(microsoftAccessToken);
    headers.setContentType(MediaType.APPLICATION_JSON);

    try {

        ObjectMapper objectMapper = new ObjectMapper();
        String jsonPayload = objectMapper.writeValueAsString(microsoftEventDto);
        System.out.println("Payload: " + jsonPayload);

        HttpEntity<String> request = new HttpEntity<>(jsonPayload, headers);
        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
        return response;
    } catch (HttpClientErrorException e) {
        System.err.println("Client Error: " + e.getStatusCode() + " - " + e.getResponseBodyAsString());
        throw e;
    } catch (HttpServerErrorException e) {
        System.err.println("Server error: " + e.getStatusCode() + " - " + e.getResponseBodyAsString());
        throw e;
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        throw new RuntimeException("Error:", e);
    }
}


@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Data
public class MicrosoftEventDto {
    private String subject;
    private ItemBody body;
    private DateTimeTimeZone start;
    private DateTimeTimeZone end;
    private Location location;
    private List<Attendee> attendees;

    @JsonProperty("isOnlineMeeting")
    private boolean onlineMeeting;

    private boolean allowNewTimeProposals = false;
    private String onlineMeetingProvider;

    @Data
    public static class ItemBody {
        private String contentType;
        private String content;
    }

    @Data
    public static class DateTimeTimeZone {
        private String dateTime;
        private String timeZone;
    }

    @Data
    public static class Location {
        private String displayName;
    }

    @Data
    public static class Attendee {
        private EmailAddress emailAddress;
        private String type;
    }

    @Data
    public static class EmailAddress {
        private String name;
        private String address;
    }
}
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,536 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,314 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. LiweiTian-MSFT 16,535 Reputation points Microsoft Vendor
    2024-06-26T02:18:49.2866667+00:00

    Hi @Dilara Ünal

    Teams tag is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your question is related to Graph Api, which is not in our support scope.The following suggestion is just for your reference:

    If you want to create an event and use it as an Online meeting, you need to enable isOnlineMeeting.

    Try: private boolean onlineMeeting = true;


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.