HOW TO
Bulk-inviting members to an ArcGIS Online group using the ArcGIS API for Python helps automate large or frequent group membership updates under consistent rules (such as role and expiration). This workflow has been validated in ArcGIS Online with both built-in and SAML logins.
The script uses the ArcGIS API for Python to connect to ArcGIS Online and uses the group.invite_users() method to send group invitations. It retrieves the target group using its Group ID and bulk-invites a list of usernames with a specified group role and invitation expiration. After sending invitations, it uses group.get_members() to identify users who are currently group members (users, admins, or owner). Users not returned by get_members() are not currently members of the group, which may indicate a pending invitation, a declined or expired invitation, an invalid username, or another condition.
from arcgis.gis import GIS
gis = GIS("home")
gis = GIS("https://www.arcgis.com", "USERNAME", "PASSWORD")
group = gis.groups.get("GroupID") #Replace with the target group’s ID
usernames = ["username1", "username2", "username3", "..."] # your bulk list
Note: Invited usernames must correspond to valid ArcGIS Online accounts. For groups that allow external membership, users from other ArcGIS Online organizations can also be invited. In such cases, the group must be configured to allow members from any organization, and the invited users must be permitted by their organization's policies to join groups outside their home organization.
invite_mem = group.invite_users(
usernames=usernames,
role="group_member", # or "group_admin"
expiration=10080 # minutes; default is 7 days
)
if invite_mem:
print(f"Invite request succeeded for: {', '.join(usernames)}")
else:
raise RuntimeError("Invite request failed (invite_users returned False).")
# Admin confirmation (accepted vs not yet accepted)
members = group.get_members() # dict: {'users': [...], 'admins': [...], 'owner': '...'}
accepted = (
set(members.get("users", []))
| set(members.get("admins", []))
| {members.get("owner")}
)
for u in usernames:
if u in accepted:
print(f"{u}: already a member (invite accepted or previously joined).")
else:
print(f"{u}: not a member yet (invite pending, declined, expired, or user not found).")
The following shows a sample of a full script:
from arcgis.gis import GIS
gis = GIS("home")
group = gis.groups.get("GroupID")
usernames = ["username1", "username2", "username3", "..."] # your bulk list
invite_mem = group.invite_users(
usernames=usernames,
role="group_member", # or "group_admin"
expiration=10080 # minutes; default is 7 days
)
# Send invitations
if invite_mem:
print(f"Invite request succeeded for: {', '.join(usernames)}")
else:
raise RuntimeError("Invite request failed (invite_users returned False).")
# Admin confirmation (accepted vs not yet accepted)
members = group.get_members() # dict: {'users': [...], 'admins': [...], 'owner': '...'}
accepted = (
set(members.get("users", []))
| set(members.get("admins", []))
| {members.get("owner")}
)
for u in usernames:
if u in accepted:
print(f"{u}: already a member (invite accepted or previously joined).")
else:
print(f"{u}: not a member yet (invite pending, declined, expired, or user not found).")
Article ID: 000042750
Get help from ArcGIS experts
Start chatting now