How to Access Private Items with REST Search Query?

1301
3
Jump to solution
03-26-2020 01:54 PM
JonM_
by
New Contributor II

How do I get my REST query to return privately owned (by me) items that are hosted on my organization's ArcGIS Online Portal? My code uses ArcGIS REST JS to create a REST search query. The query successfully returns any items of mine that I have publicly shared, but not the items that are private. I authenticate my credentials in the script using the Identity Manager from the ArcGIS API for JavaScript, and I have no problems accessing my private layers in other ways through the script.

Here's the relevant snippet:

// Authentication
var authInfo = new OAuthInfo({
    appId: myAppID,
    popup: false
});

esriId.registerOAuthInfos([authInfo]);

...

// REST JS Query
const query = new arcgisRest.SearchQueryBuilder()
        .match(myUserName)
        .in("owner")
        .and()
        .match("*")
        .in("title")

arcgisRest.searchItems(query);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Again, this query successfully returns my public but not my private items. Is there a way to pass my authentication along with the query? Any help would be appreciated.

1 Solution

Accepted Solutions
RichardHughes
New Contributor III

Hi There,

Issues logging into GeoNet so I am replying directly to email.

I’ve had a good experience using the arcgis.Portal module in the api at

3.x. TUse Portal.signIn() and it gets the portal info with the current

user from the Identify Manager. Then you can query items and get the ones

owned by yourself and or belonging to groups.

I’m not extremely proficient at the jsapi. However I do know that the

complications surrounding the restAPI are lessened when you can use an api

function call that calls the restAPI behind the scenes. That’s what the

pythonAPI does as well.

View solution in original post

0 Kudos
3 Replies
RichardHughes
New Contributor III

Hi There,

Issues logging into GeoNet so I am replying directly to email.

I’ve had a good experience using the arcgis.Portal module in the api at

3.x. TUse Portal.signIn() and it gets the portal info with the current

user from the Identify Manager. Then you can query items and get the ones

owned by yourself and or belonging to groups.

I’m not extremely proficient at the jsapi. However I do know that the

complications surrounding the restAPI are lessened when you can use an api

function call that calls the restAPI behind the scenes. That’s what the

pythonAPI does as well.

0 Kudos
JonM_
by
New Contributor II

Thank you Richard. Using the portal.queryItems functionality from the arcgis.Portal module worked great. For those interested in the code (ArcGIS JS API 4.14):

var authInfo = new OAuthInfo({
    appId: myAppID,
    popup: false
});
                
esriId.registerOAuthInfos([authInfo]);
                
var portal = new Portal();
portal.authMode = "immediate";

portal.load().then(function(){
    var queryParams = {
        query: 'owner:' + portal.user.username + ' AND title:"P*"',
        sortField: "title"
    };

    portal.queryItems(queryParams)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍;
});
AndresCastillo
MVP Regular Contributor
0 Kudos