OrgUnit not found using Google Directory APIs

Procedure

I am going to :

1. Get OrgUnit from the Google Directory API
2. Read OrgUnit and collect the necessary data
3. Try removing the OrgUnit that I just compiled.

This somehow leads to error 404 [Not Found]. Please keep in mind that the DirectoryService class that I use is working correctly.
I modified the code in this example to make it easier to read, for example: Exception handling is not enabled, etc.

API

using Google.Apis.Admin.Directory.directory_v1 

1. Get OrgUnit from the Google Directory API

 DirectoryService directoryService = ServiceInitializers.InitializeDirectoryService(); OrgUnit oUnit = directoryService.Orgunits.List(Settings.customerId).Execute().OrganizationUnits.FirstOrDefault(); 


2. Register OrgUnit and collect the required data

 string orgUnitPath = oUnit.OrgUnitPath; 


3. Try removing the OrgUnit that I just collected

 var orgUnitDeleteResult = directoryService.Orgunits.Delete(Settings.customerId, orgUnitPath).Execute(); 


An exception

GoogleApiException was not handled

An unhandled exception like "Google.GoogleApiException" occurred in Google.Apis.dll

Additional Information: Google.Apis.Requests.RequestError Authority not found [404]

+8
c # wcf google-admin-sdk google-directory-api
source share
1 answer

My reputation is not high enough to add a comment to clarify before posting a response, so I will have to make some assumptions here.

The first assumption is that you are using a service account to access the API.

The second assumption is that you have a certificate from the Google admin control panel and everything is fine.

I had a similar problem when I was updating user accounts via the API and it was found for me that the directory administrator account is a delegate for the service account.

Here is the code that I use to initialize my Google directory service.

 private static DirectoryService initializeGoogleDirectoryService() { try { String serviceAccountEmail = "your_service_account_email@developer.gserviceaccount.com"; var certificate = new X509Certificate2(@"your_certificate_name.p12", "your_secret", X509KeyStorageFlags.Exportable); // For the service account to work, a user with admin privs must be assigned as the delegate. ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { // Change the scope here to the one you need to modify org units. Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser }, User = "administrator_account@your_google_apps_domain.com" }.FromCertificate(certificate)); // Create the service. var service = new DirectoryService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Your_Application_Name" }); return service; } catch (Exception ex) { // Exception handling code below. return null; } finally { } } 
+1
source share

All Articles