0

I'm trying to develop a google script to transfer user data to (for example, a md@org.com), after deleting a user account from G Suite Admin SDK. I've tried and am unable to find it anywhere the script to transfer user data after google mail deletion. enter image description here

function onFormSubmit(e) {
 deleteUsers(e);
}
function deleteUsers() {
  var ss = SpreadsheetApp.openById('1Z0cNwh2BJLrq1bMQS3eU1tWLrjz2DLUne8CY3rMM7OE');
  var sheet = ss.getSheetByName('Delete Users');
  var data = sheet.getDataRange().getValues();

  var len = data.length;

  for(var i=1; i<len; i++){
    var user = data[i][0];
    var transferToEmail = data["Transfer to Email"][1];
    Logger.log(user);

    //use try catch in case a user is already removed
    try{
      AdminDirectory.Users.remove(user);
    }
    catch(err){}
  }
}
Naveen
  • 103
  • 1
  • 12
  • 1
    Please specify what do you mean exactly, are you referring to [Transfer data between Google Workspace accounts](https://support.google.com/a/answer/1041297?hl=en) or using the [Data Transfer API](https://developers.google.com/admin-sdk/data-transfer) – Emel Jun 09 '22 at 12:52
  • @Emel I've attached the image, using the script I need to transfer data from one user(while deleting that account) to another user account. – Naveen Jun 09 '22 at 13:37
  • Does this answer your question? [How to execute Data Transfer API?](https://stackoverflow.com/questions/65227750/how-to-execute-data-transfer-api) – Emel Jun 09 '22 at 14:39
  • @Emel No, they're using GCP. Here, the above script will delete the listed mail ids in the google sheet. Along with that, I'll provide a mail id, to which the deleted mail ids google drive data should be transferred. I think it's possible by updating the above script alone. Correct me if I'm wrong. – Naveen Jun 09 '22 at 16:19
  • 1
    As explained in the linked question, you need to use the Data Transfer API – Emel Jun 13 '22 at 07:33

1 Answers1

1

Some Google APIs are integrated with Google Apps Script as advanced services, unfortunately the Data Transfer API isn't, that is why on How to execute Data Transfer API? are using UrlFetchApp to make a HTTP request to call the Data Transfer API instead of something like AdminDirectory to call the Directory API / Reports API.

Rubén
  • 34,714
  • 9
  • 70
  • 166