0

I am trying to create Google accounts using NodeJS and return the GoogleID to a file in the working directory. I have a JSON file created in my working directory and I also have the Auth credentials saved there as well. I can read in the JSON but am getting an error when the code is executed.

Error: Invalid Given/Family Name: FamilyName

Any help would be greatly appreciated.

Here is the code. (not including the Auth stuff above this, from: https://developers.google.com/admin-sdk/directory/v1/quickstart/nodejs#step_3_set_up_the_sample)

function listUsers(auth){

  fs.readFile('user.json', function processClientSecrets(err, content) {

  if (err) {

     console.log('Error loading client secret file: ' + err);
     return;
  }

  var newUser = JSON.parse(content);

  console.log(newUser);

  console.log(newUser.First);

  console.log(newUser.Last);

  var createUser = {
     auth: auth,
     "name": {

        "givenName": newUser.First,
        "familyName": newUser.Last

    },

     "password": "aPa$$w0rd",
     "primaryEmail": newUser.District_Email,
     "changePasswordAtNextLogin": false,
     "orgUnitPath": "/Staff"
  };

  var admin = google.admin( "directory_v1");

  var id = admin.users.insert(createUser).id;


  fs.writeFile("gid.txt", "mcs" + id);

  });

}
cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Please check out the following http://stackoverflow.com/questions/18457099/how-to-create-a-user-with-the-admin-directory-api-using-the-google-api-ruby-clie as it looks to be related to your issue. – dannypaz May 04 '16 at 21:08
  • I had found that post prior. I tried to modify my code using that post but nothing was working. I do not know what is wrong with my code or what to take from the post you listed to add/change in my code to get it to work. – Scott Croskey May 06 '16 at 01:48

1 Answers1

0

var createUser =  {
  auth: auth,
  resource: {
    "name": {    
        "givenName": newUser.First,
        "familyName": newUser.Last
    },
    "password": "mcs12345",
    "primaryEmail": newUser.District_Email,
    "changePasswordAtNextLogin": false,
    "orgUnitPath": "/Staff"
  }
};
Ulion
  • 21
  • 1
  • 2