Different errors when passing string to invite_users

88
1
08-01-2019 05:30 AM
MTaft-Ferguson
New Contributor III

invite_users should actually take a list, of course. But if I pass a string by mistake/by not reading the docs closely enough, I encounter two different responses, neither of which indicates that the format was the issue, and one of which suggests there is any issue at all.

If I pass a nonsense string ("boo"), the value returned is simply True-- aka the same response as when I pass a list of valid usernames. Obviously with "boo" I wouldn't expect an actual user to have been invited, but I also get this response with invalid usernames, including for example a colleague's username with one letter missing. This non-error also occurs when I pass nonsense or invalid usernames via a list, which would make troubleshooting typos almost impossible.

If I pass a valid username as a string, though, I get the error "Unable to invite Public Account to a group owned by an organization." These users are not public accounts, they are organizational accounts owned by the same org that owns the group (OR are organizational accounts owned by a different org-- in both cases, it seems to recognize that the username is valid, even when external users' accounts are not publicly visible).

But a string is the wrong format, period. Why first of all is this not recognized or flagged in some way (an integer throws a TypeError)? Second, what is going on such that something evidently distinguishes between a string which is a valid username (in-org or not) and a string which is not even if it conforms to the same format as a proper organizational username (bsmith_umafm vs bmith_umafm, say)? 

Tags (2)
1 Reply
Mark_Peacey
Occasional Contributor

I hit the exact same problem with passing a string of users, the response is always True even though it hasn't added those users. I then passed in users from another organisation who I needed to invited to a group in our organisation and I get the error below despite them not being Public Accounts.

my_gis = gis.GIS(my_gis_url,username, password,verify_cert=False)
print("Logged into ArcGIS Online")
groupID = 'cbbbxyz'
my_group = my_gis.groups.get(groupID)

usernames = ['xyz_ETC','zzz_ETC']
new_users = my_group.invite_users(usernames, role='group_member', expiration=10080)
print(new_users)

Error:

Unable to invite Public Account to a group owned by an organization.
Traceback (most recent call last):
File "C:\Users\peaceym\OneDrive - Transpower\Python\InviteUsersToGroup.py", line 66, in <module>
new_users = my_group.invite_users(usernames, role='group_member', expiration=10080)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 4107, in invite_users
return self._portal.invite_group_users(usernames, self.groupid, role, expiration)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\portalpy.py", line 1281, in invite_group_users
postdata)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py", line 1159, in post
self._handle_json_error(resp_json['error'], errorcode)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py", line 1180, in _handle_json_error
raise RuntimeError(errormessage)
RuntimeError: Unable to invite Public Account to a group owned by an organization.
(Error Code: 400)

Atma Mani is it possible to use invite_users for inviting other Organisations' users to a group?

0 Kudos