Creating Shortcut on Google Drive using Google Apps Script


This is a sample script for creating a shortcut on Google Drive using Google Apps Script.

Sample script

Before you run the script, please enable Drive API at Advanced Google services.

function createShortcut(targetId, name, folderId) {
  const resource = {
    shortcutDetails: { targetId: targetId },
    title: name,
    mimeType: "application/",
  if (folderId) resource.parents = [{ id: folderId }];
  const shortcut = Drive.Files.insert(resource);

// Please run this function.
function main() {
  const targetId = "###"; // Please set the ID of target file or folder.
  const shortcutName = "###"; // Please set the shortcut name.
  const folderId = "###"; // Please set the folder ID for putting the created shortcut.
  const id = createShortcut(targetId, shortcutName, folderId);


  • Advanced Google services

  • Create a shortcut to a Drive file

  • Files: insert of Drive API v2

    • The official document says as follows.

      Note: Apps creating shortcuts with files.insert must specify the MIME type application/

      • But, when application/ is used, the shortcut couldn’t be created. I’m not sure whether this is the bug or the current specification. So I used application/ as the mimeType.
  • This sample script was answered to this question.