# Using the Zoom Clip API to upload Videos via Google Drive

**URL:** <https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984>\
**Category:** Authentication\
**Tags:** api\
**Created:** [October 29, 2024, 9:47am UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984 "2024-10-29T09:47:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davea](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/davea/32/52965_2.png) [@Davea](https://devforum.zoom.us/u/Davea)\
**Post date:** [October 29, 2024, 9:47am UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/1 "2024-10-29T09:47:49Z")

</div>

I have been trying to get this API call to work for a while now. This call is designed to upload new MP4 files from Google Drive to Zoom Clips. However, if you run it, you will get a 300 error. Can someone please tell me what’s going on and how to make it work?

```auto
// Function to get MP4 files from Google Drive and upload to Zoom
function getMP4FilesAndUploadToZoom() {
  var folderId = "GOOGLE-DRIVE-FOLDER-ID"; // Replace with your Google Drive folder ID
  var folder = DriveApp.getFolderById(folderId);
  
  // Fetch only MP4 files using the correct MIME type for MP4 video files
  var files = folder.getFilesByType("video/mp4");  
  
  var zoomAccessToken = getZoomAccessToken(); // Obtain Zoom Access Token
  
  if (!zoomAccessToken) {
    Logger.log("Failed to obtain Zoom Access Token");
    return;
  }
  
  while (files.hasNext()) {
    var file = files.next();
    Logger.log('MP4 file found: ' + file.getName());
    
    // Fetch the Blob (binary content) of the file
    var fileBlob = file.getBlob();
    
    // Now upload the file to Zoom Clips API
    uploadToZoomClip(fileBlob, file.getName(), zoomAccessToken);
  }
}

// Function to obtain Zoom Access Token (automatically refresh if needed)
function getZoomAccessToken() {
  var clientId = 'CLIENT-ID'; // Replace with your Zoom app Client ID
  var clientSecret = 'CLIENT-SECRET'; // Replace with your Zoom app Client Secret
  var redirectUri = 'REDIRECT-URI'; // Replace with your app redirect URI
  var tokenUrl = '-';
  
  // Retrieve tokens from Script Properties
  var accessToken = PropertiesService.getScriptProperties().getProperty('zoomAccessToken');
  var refreshToken = PropertiesService.getScriptProperties().getProperty('zoomRefreshToken');
  
  if (!accessToken || !refreshToken) {
    // No tokens, let's get authorization code
    var authorizationUrl = "/oauth/authorize?response_type=code&client_id=" + clientId + "&redirect_uri=" + redirectUri;
    Logger.log("Go to the following URL and authorize the app: " + authorizationUrl);
    // After authorization, Zoom will redirect with ?code=AUTHORIZATION_CODE, then use the authorization code to get the tokens
    return null;
  }

  // Try to refresh the access token using the refresh token
  var options = {
    method: 'post',
    headers: {
      'Authorization': 'Basic ' + Utilities.base64Encode(clientId + ':' + clientSecret),
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    payload: {
      grant_type: 'refresh_token',
      refresh_token: refreshToken
    },
    muteHttpExceptions: true
  };
  
  var response = UrlFetchApp.fetch(tokenUrl, options);
  var responseData = JSON.parse(response.getContentText());
  
  if (response.getResponseCode() === 200) {
    // Extract and store the new access token and refresh token
    var newAccessToken = responseData.access_token;
    var newRefreshToken = responseData.refresh_token;
    
    PropertiesService.getScriptProperties().setProperty('zoomAccessToken', newAccessToken);
    PropertiesService.getScriptProperties().setProperty('zoomRefreshToken', newRefreshToken);
    
    Logger.log('Zoom Access Token refreshed: ' + newAccessToken);
    return newAccessToken;
  } else {
    Logger.log('Failed to refresh Zoom Access Token. Response: ' + response.getContentText());
    return null;
  }
}

// Function to exchange the authorization code for tokens
function exchangeAuthorizationCodeForTokens(authorizationCode) {
  var clientId = 'YOUR_CLIENT_ID'; // Replace with your Zoom app Client ID
  var clientSecret = 'YOUR_CLIENT_SECRET'; // Replace with your Zoom app Client Secret
  var redirectUri = 'YOUR_REDIRECT_URI'; // Replace with your redirect URI
  var tokenUrl = '/oauth/token';

  var options = {
    method: 'post',
    headers: {
      'Authorization': 'Basic ' + Utilities.base64Encode(clientId + ':' + clientSecret),
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    payload: {
      grant_type: 'authorization_code',
      code: authorizationCode,
      redirect_uri: redirectUri
    },
    muteHttpExceptions: true
  };
  
  var response = UrlFetchApp.fetch(tokenUrl, options);
  var responseData = JSON.parse(response.getContentText());

  if (response.getResponseCode() === 200) {
    var accessToken = responseData.access_token;
    var refreshToken = responseData.refresh_token;
    
    // Store the tokens for future use
    PropertiesService.getScriptProperties().setProperty('zoomAccessToken', accessToken);
    PropertiesService.getScriptProperties().setProperty('zoomRefreshToken', refreshToken);
    
    Logger.log('Access Token: ' + accessToken);
    Logger.log('Refresh Token: ' + refreshToken);
  } else {
    Logger.log('Failed to exchange authorization code for tokens. Response: ' + response.getContentText());
  }
}

// Function to upload MP4 file to Zoom Clips API
function uploadToZoomClip(fileBlob, fileName, accessToken) {
  var url = "/v2/clips"; // Zoom Clips API endpoint for uploading clips
  
  var boundary = "Boundary-" + new Date().getTime();
  var headers = {
    "Authorization": "Bearer " + accessToken,
    "Content-Type": "multipart/form-data; boundary=" + boundary
  };
  
  // Prepare the multipart payload
  var payload =
    "--" + boundary + "\r\n" +
    "Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"\r\n" +
    "Content-Type: " + fileBlob.getContentType() + "\r\n\r\n" +
    fileBlob.getBytes() + "\r\n" + // Directly use binary data from the Blob
    "--" + boundary + "--";

  var options = {
    method: 'post',
    headers: headers,
    payload: payload, // Use the binary data directly for the payload
    muteHttpExceptions: true
  };
  
  // Make the POST request to the Zoom Clips API
  var response = UrlFetchApp.fetch(url, options);
  
  // Log the response for debugging
  Logger.log(response.getResponseCode());
  Logger.log(response.getContentText());
  
  if (response.getResponseCode() === 201) {
    Logger.log('File uploaded successfully to Zoom Clips: ' + fileName);
  } else {
    Logger.log('Failed to upload file to Zoom Clips. Response: ' + response.getContentText());
  }
}

// Manually set initial Zoom tokens after authorization
function setInitialZoomTokens() {
  var accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with the access token you got from Zoom
  var refreshToken = 'YOUR_REFRESH_TOKEN'; // Replace with the refresh token you got from Zoom
  
  PropertiesService.getScriptProperties().setProperty('zoomAccessToken', accessToken);
  PropertiesService.getScriptProperties().setProperty('zoomRefreshToken', refreshToken);
  
  Logger.log('Tokens stored successfully.');
}

// Function to check if the tokens were stored correctly
function checkStoredTokens() {
  var accessToken = PropertiesService.getScriptProperties().getProperty('zoomAccessToken');
  var refreshToken = PropertiesService.getScriptProperties().getProperty('zoomRefreshToken');
  
  Logger.log('Stored Access Token: ' + accessToken);
  Logger.log('Stored Refresh Token: ' + refreshToken);
}

```

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [October 29, 2024, 2:01pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/2 "2024-10-29T14:01:27Z")

</div>

@Davea,

Thanks for posting in the Zoom Developer Forum! First, can you share if you have been able to successfully upload one video?

---

<div class="post-metadata">

**Author:** ![Davea](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/davea/32/52965_2.png) [@Davea](https://devforum.zoom.us/u/Davea)\
**Post date:** [October 29, 2024, 2:12pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/3 "2024-10-29T14:12:10Z")

</div>

Hello Donte,

No, I have not.

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [October 29, 2024, 3:47pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/4 "2024-10-29T15:47:49Z")

</div>

@Davea ,

Can you share the link to the endpoint you are using ?

> **[Clips APIs - Zoom Developers](https://developers.zoom.us/docs/api/clips/#tag/clips)**
>
> API reference for: Clips

---

<div class="post-metadata">

**Author:** ![Davea](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/davea/32/52965_2.png) [@Davea](https://devforum.zoom.us/u/Davea)\
**Post date:** [October 29, 2024, 4:16pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/5 "2024-10-29T16:16:55Z")

</div>

“/v2/clips/files/multipart”

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [October 29, 2024, 8:55pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/6 "2024-10-29T20:55:52Z")

</div>

@Davea,

I’ve successfully upload a Zoom Clip with the following endpoint :

[https://fileapi.zoom.us/v2/clips/files](https://fileapi.zoom.us/v2/clips/files)

Can you test uploading one file on your end and let me know the results ?

> **[Zoom File Upload Process Demonstration](https://zoom.us/clips/share/nM03U1BhxREJckOwUtZXMjdvNo2Hry7HqBYj2tvjbkYB0dHqgf6Id0-jI_9wU2ygqypRujMwVJNrm-qs7I9pnxca.JbQmsW0-3yKnMnhm)**
>
> I demonstrated the process of uploading a file on Zoom. I selected a file, changed its name, and then uploaded it. The upload was successful and the file was visible in the system.

---

<div class="post-metadata">

**Author:** ![Davea](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/davea/32/52965_2.png) [@Davea](https://devforum.zoom.us/u/Davea)\
**Post date:** [October 30, 2024, 1:22pm UTC](https://devforum.zoom.us/t/using-the-zoom-clip-api-to-upload-videos-via-google-drive/119984/7 "2024-10-30T13:22:49Z")

</div>

Hello Donte,

Thank you very much. That works very well.

Your help is much appreciated.

All the best.
