Can't create email aliases in bulk for Google Workspace

0

I have a script built in .NET that creates users in bulk and also creates an alias.

Users are created in Google Admin console, however it seems that it doesn't complete the email alias information. After checking the admin console, the alternative email field is in blank

This is the error message:

Google.Apis.Requests.RequestError User creation is not complete. [412] Errors [Message[User creation is not complete.] Location[If-Match - header] Reason[conditionNotMet] Domain[global]]]

This is my script:

// create new Gmail user                    
Google.Apis.Admin.Directory.directory_v1.Data.User newuserbody = new Google.Apis.Admin.Directory.directory_v1.Data.User();
UserName newusername = new UserName();
newuserbody.PrimaryEmail = userEmail;
newusername.GivenName = sFirst;
newusername.FamilyName = sLast;
newuserbody.Name = newusername;
newuserbody.Password = sPass;

Google.Apis.Admin.Directory.directory_v1.Data.User
user = service.Users.Insert(newuserbody).Execute();
user = null;
}

catch (Exception e) {
  LogMessage("CreateGoogleEmailApps", "Error", String.Format("Google user [{0}] could not be created at this time with error: {1}", sUN, e.Message));
}

try {
  // nickname attempt
  Alias newalias = new Alias();
  newalias.AliasValue = string.Format("username-{0}@{1}", sPass, ASAS_Create.Properties.Settings.Default.G_DOMAIN);
  Alias useralias = service.Users.Aliases.Insert(newalias, userEmail).Execute();
  newalias = null;
} catch (Exception e) {
  //LogMessage("CreateGoogleEmailApps", "Error", String.Format("Google user [{0}]'s alias could not be created at this time.", sUN));                    
  LogMessage("CreateGoogleAliasApps", "Error", string.Format("Google Alias Error for user [{0}] with error message[{1}].", sUN, e.Message));
}
.net c# google-directory-api
2021-11-24 00:51:45
1

0

After some testing, I found what was going on.

The script was making requests to Google that exceeded the quota per minute, and that's why the user got created but not the email alias.

After implementing exponential backoff in https://cloud.google.com/iot/docs/how-tos/exponential-backoff the issue is resolved

2021-12-09 20:28:29

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................