Select to view content in your preferred language

PortalItem.update() ignores access changes - BUG?

364
1
03-12-2024 11:40 AM
ABREZN-CBreznicky
New Contributor

working with feature services in arcgis online.

i am using the ESRI JS SDK via esm npm package installed: 

 

 

"@arcgis/core": "^4.29.2"

 

 

i pull a list of PortalItems via PortalQueryParams: 

 

 

 import PortalQueryParams from '@arcgis/core/portal/PortalQueryParams'

 

 

then for any given item from the list, i can update it's metadata properties just fine (description, accessInformation, snippet, etc.) but when i change the "access" property, it gets ignored.

looking at the network request, clearly the "access" property is dropped by the .update() method since it is not present in the Form Data.

3fe53c55-2f03-4647-8dca-da6286876d5b.jpg

i have dove into the PortalItem .update method source code and can see where "access" is ignored when building the request form data. specifically, .update() calls a createPostQuery function, which then runs a function this.toJSON which does not include the "access" property.

9507ee33-ce14-438f-baa5-35532361530a.jpg

I have wasted hours... exploring this source code and these objects trying to figure out why it is getting ignored, and if an alternative method is required to update the sharing access that is not documented. i have had no luck. this is extremely frustrating because it should be as easy as changing the value for access. ESPECIALLY when the documentation indicates that it is possible:

https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalItem.html#update

https://developers.arcgis.com/javascript/latest/api-reference/esri-portal-PortalItem.html#access

The access property is NOT read-only like others are!

f0978bcb-8bd3-4133-8eba-3f8b1da098ff.jpg

any help with this would be extremely appreciated!

i see the capabilities to accomplish this using the REST api but it seems ridiculous to me that such a simple change would require a whole separate set of requests when i am already authenticated and updating the portal item.

0 Kudos
1 Reply
LaurenBoyd
Esri Contributor

Hi @ABREZN-CBreznicky -

Unfortunately, you cannot update the access of a portal item using the PortalItem.update() method. We will get the documentation updated to outline the PortalItem properties that are read-only (including access).

When changing the sharing level of an item, you will have to use the /share endpoint since we don't have a method to update the sharing level of an item: https://developers.arcgis.com/rest/users-groups-and-items/share-item-as-item-owner-.htm 

I made a small example showing how esriRequest can be used to update the sharing level of an item: https://codepen.io/laurenb14/pen/qBwaYpO?editors=1000 Only the query string in the PortalQueryParameters should need to be changed to the get the items you are looking for.

Hope this helps!

Lauren
0 Kudos