Google Provisioning API no longer allowing restore(unsuspend) of user
Question: Anybody else seeing this? There appears to have been some changes to the
Google provisioning api for multi-domains. I have long running code that could
restore a suspended user that has stopped working. I use Python and 2.0.17 of
the Python GData libraries and the UpdateUser method to do this. I have also
noted that RetrieveUser in the same library is no longer returning the first
and last names of suspended users. I have filed an issue at Google apps-api-
issues, please star if you are seeing this.

<http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3281>


Answer: This is a simple example that will walk through the problem. Note that
user_entry object returned from a RetrieveUser() on a suspended user will not
have a property value for either first name or last name. The modified
user_entry object is passed to UpdateUser() which does not allow the missing
values for first and last names.

    
    
    #!/usr/bin/python
    import sys
    import gdata.apps.multidomain.client
    
    if len(sys.argv) < 4:
      print "\nUsage:"
      print sys.argv[0], "admin_email admin_password user_email\n"
      sys.exit(0)
    
    admin = sys.argv[1]
    password = sys.argv[2]
    email = sys.argv[3]
    domain = ""
    if '@' in admin:
      admin_name,domain = admin.split('@', 1)
    else:
      print "Specify full email address of administrator.\n"
      print "\nUsage:"
      print sys.argv[0], "admin_email admin_password user_email\n"
      sys.exit(0)
    if '@' not in email:
      print "Specify full email address of user.\n"
      print "\nUsage:"
      print sys.argv[0], "admin_email admin_password user_email\n"
      sys.exit(0)
    
    md_client = gdata.apps.multidomain.client.MultiDomainProvisioningClient(
      domain=domain)
    md_client.ClientLogin(email=admin, password=password, source='MDPROVISIONING')
    print "Retrieve user: %s\n" %(email)
    user_entry = md_client.RetrieveUser(email)
    print user_entry
    print ('\nRetrieve results: email: %s, suspended: %s,'
      ' first name: %s, last name: %s\n' 
      %(user_entry.email,user_entry.suspended,
        user_entry.first_name,user_entry.last_name))
    print "Update user (suspend): %s\n" %(email)
    user_entry.suspended = 'true'
    updated_user_entry = md_client.UpdateUser(email, user_entry)
    print updated_user_entry
    print ('\nSuspend results: email: %s, suspended: %s,'
      ' first name: %s, last name: %s\n' 
      %(updated_user_entry.email,updated_user_entry.suspended,
        updated_user_entry.first_name,updated_user_entry.last_name))
    print "Retrieve user: %s\n" %(email)
    user_entry = md_client.RetrieveUser(email)
    print user_entry
    print ('\nRetrieve results: email: %s, suspended: %s,'
      ' first name: %s, last name: %s\n' 
      %(user_entry.email,user_entry.suspended,
        user_entry.first_name,user_entry.last_name))
    print "Update user (restore): %s\n" %(email)
    user_entry.suspended = 'false'
    updated_user_entry = md_client.UpdateUser(email, user_entry)
    print updated_user_entry
    print ('\nRestore results: email: %s, suspended: %s,'
      ' first name: %s, last name: %s\n' 
      %(updated_user_entry.email,updated_user_entry.suspended,
        updated_user_entry.first_name,updated_user_entry.last_name))
    

