Search code examples
permissionsgoogle-drive-apiservice-accounts

How to prevent "Delivery Status Notification (Failure)" when using service account


enter image description here

I am using a web application to create and share write permission in a google drive folder through service account. The creation and permission sharing successfully performed.

I am using below code to create this permission.

function createPermissionOffic(auth){
  const drive = google.drive({version: 'v3', auth});

  var fileId = rootFolderId;
  var permissions = [
    {
      'type': 'user',
      'role': 'writer',
      'emailAddress': serviceAccountEmail
    }
  ];
  // Using the NPM module 'async'
  async.eachSeries(permissions, (permission, permissionCallback)=> {
    drive.permissions.create({
      resource: permission,
      fileId: fileId,
      fields: 'id',
      sendNotificationEmails: false
    }, (err, res)=> {
      if (err) {
        // Handle error...
        console.error(err);
        permissionCallback(err);
      } else {
        console.log('Permission ID: '+ res)
        permissionCallback();
      }
    });
  }, (err)=> {
    if (err) {
      // Handle error
      console.error(err);
    } else {
      // All permissions inserted
      
    }
  });

}

I was hoping that " sendNotificationEmails: false" will prevent any such mail notification. How to solve this issue?


Solution

  • I think that the reason of your issue is due to the spell mistake. So please modify as follows and test it again.

    From:

    sendNotificationEmails: false
    

    To:

    sendNotificationEmail: false
    
    • Please remove the last character s of sendNotificationEmails.

    Reference: