0

I'm using Google's Admin SDK to provision user accounts, but when I try to set the primary Email account using

Alias alias = new Alias();
alias.setAlias(primaryEmailAddress);
alias.setPrimaryEmail(primaryEmailAddress);
directory.users.().aliases().insert(userName, alias).execute();

where primaryEmailAddress is a String, I get

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400       
Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Input: 387235917385, email.address@domain.com",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Input: 387235917385, email.address@domain.com"
}

Is this the correct way to go about setting a user's primary email address?

S McKinley
  • 48
  • 6
  • When you pass your values into the [API explorer](https://developers.google.com/admin-sdk/directory/v1/reference/users/aliases/insert) (the try it section), does it work? – Andy Mar 09 '15 at 17:26
  • No, but the error returned is not the same error and isn't real helpful either. I authorized the API call using Oauth but the error is a 403 - Not authorized to access this resource. – S McKinley Mar 09 '15 at 18:42
  • Top right of the try it section there's a switch to enable OAuth, make sure you have done that. – Andy Mar 09 '15 at 19:27
  • I authorized the app using that switch. Sorry, should have mentioned that. – S McKinley Mar 09 '15 at 20:22
  • If you're using the Java libraries, maybe you can try [setPrimaryEmail()](https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/java/latest/com/google/api/services/admin/directory/model/User.html#setPrimaryEmail(java.lang.String)) – Andy Mar 09 '15 at 20:53
  • I tried setting the primary email for the user and then updating the user via the directory object, but got an error message about the user already existing. After some additional investigation, I believe that what I'm trying to accomplish is done using the createSendAs() method of the GmailSettingsService class, which, while not deprecated, uses the old style of authentication. – S McKinley Mar 10 '15 at 15:46

0 Answers0