0

I created a script for my Google Form that will add a user to Google Admin. It was running fine yesterday, but today when I run it, it gives met the following error:

GoogleJsonResponseException: API call to directory.users.insert failed with error: Domain not found.

Any idea what may have caused this? Here is the relevant snippet of my code:

    AdminDirectory.Users.insert(user); //adds user to google admin
    Logger.log('User %s created with PW %s.', user.primaryEmail, user.password);

I have also included the following services: enter image description here

**EDIT: Also, I have Apps Access Control set to unrestricted for Apps Script Runtime, Apps Script API, and Google Drive.

JAck28
  • 899
  • 4
  • 15
  • 40
  • can you confirm if you used the correct domain name in `user.primaryEmail`. I was able to add a new user using a valid domain and when I used an invalid domain, I encountered the same error as you did. example: user1@invaliddomain.com – Ron M Dec 17 '20 at 18:49
  • omg, yes! Thank you!! Make it an answer, and I'll accept! – JAck28 Dec 17 '20 at 19:05
  • No problem, thank you as well. – Ron M Dec 17 '20 at 19:56

1 Answers1

0

Domain not found error will occur if you input an incorrect domain name in your primary email when adding a user.

Sample Code (Issue will be seen):

var user = {
    primaryEmail: 'user1@invaliddomain.com',
    name: {
      givenName: 'Test',
      familyName: 'Test'
    },
    // Generate a random password string.
    password: 123456789
  };

  var user = AdminDirectory.Users.insert(user);
  Logger.log(user);
Ron M
  • 5,791
  • 1
  • 4
  • 16