cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error updating Preferred Name ( New First and Last name )

Error updating Preferred Name ( New First and Last name )

JohnAdam_CUNY
Helpful | Level 6

We got a requirement to update our Dropbox first and last name. Is it simply to to use info to update an existing user Dropbox first name and last name. Our wrote the code using json API but not as familiar with Python SDK. Any help is greatly appreciated

 I tried below but it doesnt update the data.

 

 

user = dropbox.team.UserSelectorArg.email(dropboxemail)
result = dbx_team.team_members_get_info_v2([user])
print(result)

for info in result.members_info:
if info.is_member_info():
print("\n\nName is : " + str(info.get_member_info().profile.name) )
print("\n\nFirst Name is : " + str(info.get_member_info().profile.name.given_name))
print("\n\nLast Name is : " + str(info.get_member_info().profile.name.surname))

print("Account ID : " + info.get_member_info().profile.team_member_id)
print("Email is : " + info.get_member_info().profile.email)
print("\nPersistent ID is : " + info.get_member_info().profile.persistent_id)
print("External ID is : " + info.get_member_info().profile.external_id)

1 Accepted Solution

Accepted Solutions

JohnAdam_CUNY
Helpful | Level 6
Go to solution

Documentation is not clear. See solution. Please advise if I misunderstood anything.


team_members_set_profile_v2(user, new_email=None, new_external_id=None, new_given_name=None, new_surname=None, new_persistent_id=None, new_is_directory_restricted=None)


if len(fname) != 0:
result = dbx_team.team_members_set_profile_v2(user=user, new_given_name=fname)
print(result)
if len(lname) != 0:
result = dbx_team.team_members_set_profile_v2(user=user, new_surname=lname)
print(result)

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff

In the code snippet you shared here, I see you're calling team_members_get_info_v2, which is a way to read the information for some team member(s). That doesn't change their information on Dropbox. If you want to change their member information (like first/last name) you should use team_members_set_profile_v2.

 

In any case, if something isn't working as expected, please share both the code and the unexpected error or output. (I see you mentioned getting an error in the title for this thread, but it doesn't look like you included that error output here.)

JohnAdam_CUNY
Helpful | Level 6
Go to solution

I checked the documentation but looking for clarification since we still use the old json API for 95% of our teams we are learning the new Python SDK for 1 team.


Instead of user do I pass the below. Can you provide an example of updating fname and lname for below?


## New Code
user = dropbox.team.UserSelectorArg.email(dropboxemail)
result = dbx_team.team_members_set_profile_v2([user])
print(result)

 


##OlD Get Info Code
for info in result.members_info:
if info.is_member_info():

if len(new_email) != 0:
info.get_member_info().profile.email = new_email
if len(fname) != 0:
info.get_member_info().profile.name.given_name = fname
if len(lname) != 0:
nfo.get_member_info().profile.name.surname = lname
if len(emplid) != 0:
info.get_member_info().profile.persistent_id = emplid
if len(newExID) != 0:
info.get_member_info().profile.external_id = newExID
#######################################################################################
print("\n\nName is : " + str(info.get_member_info().profile.name) )
print("\nFirst name is : " + str(info.get_member_info().profile.name.given_name))
print("Last Name is : " + str(info.get_member_info().profile.name.surname))
print("Account ID : " + info.get_member_info().profile.team_member_id)
print("Email is : " + info.get_member_info().profile.email)
print("\nPersistent ID is : " + info.get_member_info().profile.persistent_id)
print("External ID is : " + info.get_member_info().profile.external_id)
elif info.is_id_not_found():
print("User not found.")
else:
print("Other scenario not anticipated. Need to traige...")

Greg-DB
Dropbox Staff
Go to solution

@JohnAdam_CUNY I don't believe we have sample code handy for team_members_set_profile_v2 in particular, so please refer to the documentation for information on the parameters to use with that method. For example, it sounds like you'd need to use the "user", "new_given_name", and "new_surname" for your use case.

 

Please try that out and if it doesn't work for you, please share the relevant code and output so we can help troubleshoot.

JohnAdam_CUNY
Helpful | Level 6
Go to solution

See below issue it appears not to accept my variables.

 

Test #1

dbx_team = dropbox.DropboxTeam(
oauth2_refresh_token=REFRESH_TOKEN,
app_key=APP_KEY,
app_secret=APP_SECRET)
user = dropbox.team.UserSelectorArg.email(dropboxemail

if len(new_email) != 0:
result = dbx_team.team_members_set_profile_v2([user],new_email=new_email)
print(result)
if len(fname) != 0:
result = dbx_team.team_members_set_profile_v2([user],info.get_member_info().profile.name.given_name = fname)
print(result)
if len(lname) != 0:
result = dbx_team.team_members_set_profile_v2([user], info.get_member_info().profile.name.new_surname=lname)
print(result)


Error:
C:\Users\jdebh\Anaconda3\python.exe "S:\Academic Collaboration Technology\DROP BOX\DropboxPROD\CORECODE\OAUTH_COSEN_SET_INFO.py"
File "S:\Academic Collaboration Technology\DROP BOX\DropboxPROD\CORECODE\OAUTH_COSEN_SET_INFO.py", line 30
result = dbx_team.team_members_set_profile_v2([user],info.get_member_info().profile.name.given_name = fname)
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

Process finished with exit code 1


Test #2

dbx_team = dropbox.DropboxTeam(
oauth2_refresh_token=REFRESH_TOKEN,
app_key=APP_KEY,
app_secret=APP_SECRET)
user = dropbox.team.UserSelectorArg.email(dropboxemail)

 

if len(new_email) != 0:
result = dbx_team.team_members_set_profile_v2([user],new_email=new_email)
print(result)
if len(fname) != 0:
result = dbx_team.team_members_set_profile_v2([user], new_given_name=str(fname))
print(result)
if len(lname) != 0:
result = dbx_team.team_members_set_profile_v2([user], new_surname=str(lname))
print(result)

Error:
Traceback (most recent call last):
File "S:\Academic Collaboration Technology\DROP BOX\DropboxPROD\CORECODE\OAUTH_COSEN_SET_INFO.py", line 32, in <module>
result = dbx_team.team_members_set_profile_v2([user], new_given_name=str(fname))
File "C:\Users\jdebh\Anaconda3\lib\site-packages\dropbox\base_team.py", line 2065, in team_members_set_profile_v2
arg = team.MembersSetProfileArg(user,
File "C:\Users\jdebh\Anaconda3\lib\site-packages\dropbox\team.py", line 9112, in __init__
self.user = user
File "C:\Users\jdebh\Anaconda3\lib\site-packages\stone\backends\python_rsrc\stone_base.py", line 79, in __set__
self.validator.validate_type_only(value)
File "C:\Users\jdebh\Anaconda3\lib\site-packages\stone\backends\python_rsrc\stone_validators.py", line 612, in validate_type_only
raise ValidationError('expected type %s or subtype, got %s' %
stone.backends.python_rsrc.stone_validators.ValidationError: expected type dropbox.team.UserSelectorArg or subtype, got list

JohnAdam_CUNY
Helpful | Level 6
Go to solution

Documentation is not clear. See solution. Please advise if I misunderstood anything.


team_members_set_profile_v2(user, new_email=None, new_external_id=None, new_given_name=None, new_surname=None, new_persistent_id=None, new_is_directory_restricted=None)


if len(fname) != 0:
result = dbx_team.team_members_set_profile_v2(user=user, new_given_name=fname)
print(result)
if len(lname) != 0:
result = dbx_team.team_members_set_profile_v2(user=user, new_surname=lname)
print(result)

Greg-DB
Dropbox Staff
Go to solution

In your first attempt, I see you're putting other statements in place of the method's parameter names, which is not valid Python code, so you get that SyntaxError.

 

In your second attempt, I see you're supplying a list of UserSelectorArg, that is `[user]`, instead of just a single UserSelectorArg as documented, that is just `user`, so you get that ValidationError.

 

In your third attempt, I see you are using the correct parameter names and types, but note that you don't need to call it three times. It looks like you're not setting anything on that first call, so that one seems unnecessary. Edit: unless that first line is just copied from the documentation, and not something you're actually running?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    JohnAdam_CUNY Helpful | Level 6
What do Dropbox user levels mean?