Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Last active January 29, 2021 16:00
Show Gist options
  • Save balvinder294/6bc682c8b9b5f007ef516bbb54bd5516 to your computer and use it in GitHub Desktop.
Save balvinder294/6bc682c8b9b5f007ef516bbb54bd5516 to your computer and use it in GitHub Desktop.
Method to set up scheduled meeting in Java using Zoom Rest Api for Zoom Meetings - https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate | By https://tekraze.com
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
public ZoomMeetingObjectDTO createMeeting(ZoomMeetingObjectDTO zoomMeetingObjectDTO) {
log.debug("Request to create a Zoom meeting");
// replace zoomUserId with your user ID
String apiUrl = "https://api.zoom.us/v2/users/" + zoomUserId + "/meetings";
// replace with your password or method
zoomMeetingObjectDTO.setPassword(yourPass);
// replace email with your email
zoomMeetingObjectDTO.setHost_email("yourEmail");
// Optional Settings for host and participant related options
ZoomMeetingSettingsDTO settingsDTO = new ZoomMeetingSettingsDTO();
settingsDTO.setJoin_before_host(false);
settingsDTO.setParticipant_video(true);
settingsDTO.setHost_video(false);
settingsDTO.setAuto_recording("cloud");
settingsDTO.setMute_upon_entry(true);
zoomMeetingObjectDTO.setSettings(settingsDTO);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Bearer " + generateZoomJWTTOken());
headers.add("content-type", "application/json");
HttpEntity<ZoomMeetingObjectDTO> httpEntity = new HttpEntity<ZoomMeetingObjectDTO>(zoomMeetingObjectDTO, headers);
ResponseEntity<ZoomMeetingObjectDTO> zEntity = restTemplate.exchange(apiUrl, HttpMethod.POST, httpEntity, ZoomMeetingObjectDTO.class);
if(zEntity.getStatusCodeValue() == 201) {
log.debug("Zooom meeeting response {}",zEntity);
return zEntity.getBody();
} else {
log.debug("Error while creating zoom meeting {}", zEntity.getStatusCode());
}
return zoomMeetingObjectDTO;
}
/**
* Generate JWT token for Zoom using api credentials
*
* @return JWT Token String
*/
private String generateZoomJWTTOken() {
String id = UUID.randomUUID().toString().replace("-", "");
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
Date creation = new Date(System.currentTimeMillis());
Date tokenExpiry = new Date(System.currentTimeMillis() + (1000 * 60));
Key key = Keys
.hmacShaKeyFor(zoomApiSecret.getBytes());
return Jwts.builder()
.setId(id)
.setIssuer(zoomApiKey)
.setIssuedAt(creation)
.setSubject("")
.setExpiration(tokenExpiry)
.signWith(key, signatureAlgorithm)
.compact();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment