Create a user

If assigned the Admin role for a resource, you can create a user with access to that resource or those under it.

Users are created through the user.create method.

A new user's email address must have a corresponding Google Account, which can be created for an existing email address. The user resource created must also include at least one assigned user role.

The following code is an example of how to create a new user with standard access to an advertiser:

Java

// Create the user structure.
User user = new User();
user.setEmail(email-address);
user.setDisplayName(display-name);

// Create the assigned user role structure.
AssignedUserRole assignedUserRole = new AssignedUserRole();
assignedUserRole.setAdvertiserId(advertiser-id);
assignedUserRole.setUserRole("STANDARD");

// Add assigned user role list to the user.
user.setAssignedUserRoles(ImmutableList.of(assignedUserRole));

// Configure the create request.
Users.Create request = service.users().create(user);

// Create the user.
User response = request.execute();

// Display the user.
System.out.printf("User %s was created with email %s.",
    response.getName(),
    response.getEmail());

Python

# Create a user object.
user_obj = {
    'email': email-address,
    'displayName': display-name,
    'assignedUserRoles': [
        {
            'advertiserId': advertiser-id,
            'userRole': 'STANDARD'
        }
    ]
}

# Build request.
request = service.users().create(
    body=user_obj
)

# Execute request.
response = request.execute()

# Display the new user.
print('User %s was created with email %s.'
      % (response['name'], response['email']))