Select to view content in your preferred language

Scripting creation of Shared Update Group ArcGIS API for Python

181
3
Jump to solution
Monday
carlyrobbins1
Emerging Contributor

I am trying to script creating a shared update group using ArcGIS API for Python. I only want members from my organization to be able to join, and all members of the group can contribute content.

 

I am able to create the group manually, but I am getting an error when I script it. In my code, I am cloning an existing shared update group and renaming it, and this is the error.

Invalid membership access for group with update capabilities.
(Error Code: 400)

 

Here is the code:

from arcgis.gis import GIS
import arcgis
from IPython.display import display
print (arcgis.__version__)

#Define the source and target portals. They are both the same in our case. You should be signed into the organization's GeoPlatform when you run this script. You must have Publisher privileges to be able to create a new group.
source = GIS("home")
target = GIS("home")
#search for the shared updated group to be cloned
source_shared_groups = source.groups.search("title: OCS NSD ER Dashboard Training (NOAA Internal Only) AND owner:ocs.nrb_noaa")
source_shared_groups
source_shared_group = source_shared_groups[0]
source_shared_group

 

import tempfile

#Define new name for the cloned group. ****REPLACE "New Shared Group Name" with the name of your new group.****
new_shared_group_name = "New Shared Group Name (Internal Only)"

#Checks for the existence of the new group name. This prevents the "already exists" message from appearing. It will not overwrite a group that already exists with the same name as your new group name.
if not target.groups.search(new_shared_group_name):
    try:
        with tempfile.TemporaryDirectory() as temp_dir:
            shared_thumbnail_file = source_shared_group.download_thumbnail(temp_dir)

            # Create a group in the target portal with the new name
            target_shared_group = target.groups.create(title=new_shared_group_name,
                                                 tags=source_shared_group.tags,
                                                 description=source_shared_group.description,
                                                 snippet=source_shared_group.snippet,
                                                 access="private",
                                                 thumbnail=shared_thumbnail_file,
                                                 is_invitation_only=True,
                                                 sort_field='avgRating',
                                                 sort_order='asc',
                                                 is_view_only=False,
                                                 users_update_items = True)
            # Display the new group
            display(target_shared_group)

    except Exception as e:
        print('Group {} could not be created'.format(new_shared_group_name))
        print(e)
else:
    print('Group {} already exists in the portal'.format(new_shared_group_name))
    target_shared_group = target.groups.search(new_shared_group_name)[0]

 

If I say users_update_items = False, it creates the group but it is not a shared update group.

 

Is this really a problem with my admin privileges if I can make the shared update group manually, or is there something wrong with the code?

 

Thanks!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
PeterKnoop
MVP Regular Contributor

The default for membership_access is "none", which permits membership from any organization. That is not compatible with a Shared Update group (i.e., with users_update_items set to True), hence the error you are seeing. 

To address the issue, add the membership_access parameter to your call to create_group, explicitly setting it to "org" or "collaboration", as appropriate for your needs.

 

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor

moved to the arcgis-api-for-python-questions


... sort of retired...
0 Kudos
PeterKnoop
MVP Regular Contributor

The default for membership_access is "none", which permits membership from any organization. That is not compatible with a Shared Update group (i.e., with users_update_items set to True), hence the error you are seeing. 

To address the issue, add the membership_access parameter to your call to create_group, explicitly setting it to "org" or "collaboration", as appropriate for your needs.

 

carlyrobbins1
Emerging Contributor

thank you! This worked!

0 Kudos