0

Same problem whether I try the API Explorer https://developers.google.com/admin-sdk/directory/v1/reference/orgunits/delete#try-it or when using the .NET API.

I have a simple integration test that creates a new Orgunit + User under that orgunit.

Then I do this:

  1. List all users that match that orgunit path
  2. Delete them successfully
  3. Try to delete the orgunit itself => 404

I know the orgunit is still there. I can go into API Explorer and list it here https://developers.google.com/admin-sdk/directory/v1/reference/orgunits/list

enter image description here

If I try to delete it now in API Explorer, no such luck. I also tried using my root OU's real customer id (instead of my_customer). Still no luck.

enter image description here

The only way I can delete this orgunit is through the admin console.

enter image description here

This succeeds -- there were no sub-orgs or users underneath this org, or it would have failed.

enter image description here

Why can I not delete the Orgunit through the API or API Explorer?

zenocon
  • 1,597
  • 1
  • 17
  • 24
  • Did you verify if you provided the correct customerId during deletion? Can you try a specific customerId not my_customer for debugging purposes? – ReyAnthonyRenacia May 11 '18 at 11:47
  • Yes, I verified the right "C" customerId. Tried literally everything. I am absolutely confident that this API does not work. I am not the only person that has filed this. A couple other SO links, and there is an issue in Google's issue tracker which I upvoted. Just tough to believe it has been broken for this long and *no-one* has addressed it? I must be one of the few people to actually try to use it, but that seems impossible given their scale. – zenocon May 13 '18 at 01:04
  • Alright, can you provide the issue tracker link so other devs might see it. – ReyAnthonyRenacia May 14 '18 at 06:14
  • Sure, here it is: https://issuetracker.google.com/issues/63418725 – zenocon May 14 '18 at 16:12

1 Answers1

0

You can delete a list of OU's with the following Google Apps Script you can embed in a Google Sheets document.

  • You need admin privileges to run the script.
  • The script points to an active Google Sheet where you have two sheets: OrgUnits and Log.
  • The sheet named OrgUnits has two columns: one for orgUnitPath and another for orgUnitId.
  • Your customer id is stored in the variable CUSTOMER_ID.
  • Warning, eventually you get errors related with "Request rate higher than configured", just isolate the cases and retry them.

Here is the script:

function DeleteOrgUnits(){
  var inputSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("OrgUnits");
  var outputSheetLog = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Log");  
  var dataValues =   inputSheet.getDataRange().getValues();
  var i, err, errObj;
  var orgUnit, orgUnitItem, orgUnitId = [], orgUnitPath;
  var customerId = CUSTOMER_ID;
  
  outputSheetLog.getDataRange().clear();


  if (dataValues){
    for ( i in dataValues ){
      orgUnit = dataValues[ i ];
      orgUnitPath = orgUnit[ 0 ];
      orgUnitId = orgUnit[ 1 ];
      if (orgUnitPath.length > 0 ){
        err = false;
        try { 
          orgUnitItem = AdminDirectory.Orgunits.remove(customerId, orgUnitId);
        } catch(e){ err = true; errObj = e; };
        if (err)
          outputSheetLog.appendRow([orgUnitPath, 'Error', orgUnitItem, errObj.message ]); 
        else
          outputSheetLog.appendRow([orgUnitPath, 'Deleted', orgUnitItem ]);
      }
    }
    outputSheetLog.appendRow(['Done!']);
  } else {
    outputSheetLog.appendRow(['No Data!']);
  }
}