Authentication Error When Accessing Living Atlas Layers in R Using arcgisutils and arcgislayers Packages

89
3
Jump to solution
yesterday
KevinBoes2
Emerging Contributor

I am performing spatial data analysis within R Studio using datasets stored in our ArcGIS Enterprise. To access these datasets, I am using the arcgisutils and arcgislayers packages, and I've set up an authenticator application in our enterprise portal which allows me to connect to our portal in R Studio using user authentication. 

I have been successfully accessing data stored within our enterprise portal using the following steps:

  1. Obtain the service url for the desired sublayer in a feature layer item using the item's itemID within the arcgislayers::arc_open() function, and passing the result to the arcgislayers::get_layer() function
  2. Extract the desired sublayer as an sf object using the service url within the arcgislayers::arc_open() function, and passing the result to the arcgislayers::arc_select() function

When I try applying this workflow to data accessible in the Living Atlas, though, I receive a 498 error and a message that the token is invalid. Based on backtracing, it appears that the error is being thrown during the first step of the workflow.

When I navigate to the Living Atlas item in our portal interface, I can open the dataset in a map or view the data table in the Data view without any authentication issues. So, I don't think the issue is that my arcgis login just hasn't had that content shared with it. Is it possible that access to Living Atlas items in the portal interface is driven by a different mechanism than access to items stored in our enterprise, and that this difference in mechanisms is being exposed when trying to connect to the Living Atlas items in R Studio?

0 Kudos
1 Solution

Accepted Solutions
VenkataKondepati
Regular Contributor

Many Living Atlas items ultimately resolve to services hosted on ArcGIS Online (*.arcgis.com) or external endpoints.

Your Enterprise token is valid for your Enterprise domain, but not valid for ArcGIS Online, so the request gets 498.

Check the layer’s actual service URL. If it’s services.arcgis.com / utility.arcgis.com, you must authenticate against ArcGIS Online (or access it anonymously if public).

In R: open the service URL directly (not just itemId), and use the correct auth context for that host.

If your org uses subscriber content, you may need an AGOL OAuth token (same user) in addition to Enterprise auth.

Token must match the host that serves the data.

View solution in original post

0 Kudos
3 Replies
VenkataKondepati
Regular Contributor

Many Living Atlas items ultimately resolve to services hosted on ArcGIS Online (*.arcgis.com) or external endpoints.

Your Enterprise token is valid for your Enterprise domain, but not valid for ArcGIS Online, so the request gets 498.

Check the layer’s actual service URL. If it’s services.arcgis.com / utility.arcgis.com, you must authenticate against ArcGIS Online (or access it anonymously if public).

In R: open the service URL directly (not just itemId), and use the correct auth context for that host.

If your org uses subscriber content, you may need an AGOL OAuth token (same user) in addition to Enterprise auth.

Token must match the host that serves the data.

0 Kudos
KevinBoes2
Emerging Contributor

Thank you for this advice, @VenkataKondepati! Prior to setting my enterprise token, I ran the arc_open() function using the service url rather than the itemID, and the function accessed the layer successfully! I reran the function after setting my enterprise token, and I got a different error from the arc_select() function stating that it couldn't determine the number of requested features. Explicitly setting the token parameter in the arc_select() function to NULL circumvented this error, though, allowing me to access the layer even after I'd set my enterprise token. If this error is being thrown in response to an invalid token in this instance, it might be useful if the function could throw a token-specific error instead.

I think this gets me everything I need to access items shared with my user from our enterprise portal and the Esri Living Atlas.

VenkataKondepati
Regular Contributor

Thanks for the feedback. @KevinBoes2 
I am glad you figured it out.

Regards,
Venkat

0 Kudos