REST to find all Maps in the organization - Separated by user

6192
10
Jump to solution
08-21-2013 03:41 PM
ChrisThomas4
New Contributor II
This is my current problem, and I have a feeling that I'm just missing some of the ArcGIS 'lingo' that would make this easily explainable.

So I need to grab all the maps available in my organization, and I know how to use
http://www.arcgis.com/sharing/rest/content/users/' + username + '/' to grab all the content in the home directory of that user, and
http://www.arcgis.com/sharing/rest/content/users/' + username + '/' + folder_id (User-Content) to get all the content in that user's folder at folder_id. I can then iterate over the resulting items and grab out all the web maps or what-have-you.
The above needs to be done for each user in the organization.
The trouble is, this organization is in a constant state of user-flux. So I cannot just store all the organization's users in an array and do this for every user in it; I need to be able to get a list of all the users in the organization. I have an administrator account, so I expect I will be able to see all the content in rest just like I could in ArcGIS Online.

The trouble is the REST API doesn't appear to have any means of searching for the users in an organization directly; they would have to all be members of the same group (which they aren't and I'd rather not force that), or I would have to specify the organization in a query to <community-url>/users?q= (User-Search), which doesn't appear to be possible, unless specifying access: org applies to users, which doesn't logically make sense to me.

So I guess my question is, is this possible? Can I search for the users in a given organization using REST? Would it be by finding the organization's web-portal's ID and use portal->users (portal->users)? Is a standard organization's 'My Organization' actually a portal? Where would I find that ID if it is? More swirling questions?

Thanks in advance, to any and all.
1 Solution

Accepted Solutions
AnttiKajanus1
Occasional Contributor III
Hi,
From my understanding ArcGIS Online also contains "portal".

You can get users for example like this
GET http://www.arcgis.com/sharing/rest/community/users?num=100&q=orgid%yourorganizationid&f=json& HTTP/1.1


This orgid is your organizational id that you can see atleast from your My organization page where you need to ckeck queries from the right (ie. The most viewed items in the organization ). If you check the link you can spot the id from there. I haven't seen really good place get that information so I have been using this way to get it from AGOL directly.

If you do query without authentication token you get only public accounts and if you are authenticated I think you get all.

For fast testing here is example in WPF (that generates earlier request to REST endpoint)
var portal = new ArcGISPortal();               portal.SearchUsersAsync(new SearchParameters() { Limit = 100, QueryString = "orgid:YourId" }, (info, exception) =>                 {                    if (info != null)                    {                        MessageBox.Show(info.Results.Count().ToString());                    }                 });

View solution in original post

10 Replies
AnttiKajanus1
Occasional Contributor III
Hi,
From my understanding ArcGIS Online also contains "portal".

You can get users for example like this
GET http://www.arcgis.com/sharing/rest/community/users?num=100&q=orgid%yourorganizationid&f=json& HTTP/1.1


This orgid is your organizational id that you can see atleast from your My organization page where you need to ckeck queries from the right (ie. The most viewed items in the organization ). If you check the link you can spot the id from there. I haven't seen really good place get that information so I have been using this way to get it from AGOL directly.

If you do query without authentication token you get only public accounts and if you are authenticated I think you get all.

For fast testing here is example in WPF (that generates earlier request to REST endpoint)
var portal = new ArcGISPortal();               portal.SearchUsersAsync(new SearchParameters() { Limit = 100, QueryString = "orgid:YourId" }, (info, exception) =>                 {                    if (info != null)                    {                        MessageBox.Show(info.Results.Count().ToString());                    }                 });
ChrisThomas4
New Contributor II
THANK YOU. Very clever of you to notice that query parameter in the browser, which, by the way, isn't in the API documentation for searches. That made all the difference, so now my script is complete.
I haven't seen really good place get that information so I have been using this way to get it from AGOL directly.

Isn't it odd that they would neither document it, nor give you easy access to your organization's id? You would think that it would be documented and accessible if it has practical uses. Maybe I'll put in a feature request for that; I'm getting a little sick of how poorly organized the rest api reference is. I spend twice as much time mucking through poorly explained terminology and disorganized folders as I do actually programming.
Anyway, I digress.

Again, a thousand thanks, antti.kajanus. Marked.
AndresCastillo
MVP Regular Contributor

In case anyone needs it:

For ArcGIS Online, the org id is listed in:

https://<orgName>.maps.arcgis.com/sharing/rest/portals/self?f=json&token=

the json format and token must be provided, as it seems you can't navigate this endpoint using html, nor without a token.

Look for the value of the user.orgId key

For Portal for ArcGIS that uses AD SSO, the orgid is listed in:

https://<hostMachine>/portal/sharing/rest/portals/self 

https://<hostMachine>/portal/sharing/rest/portals/self?f=pjson 

The json format is optional.

The token seems to be read from your SSO on your network, so it does not need to be provided.

Look for the value of the id key

0 Kudos
IanStewart41
New Contributor

I would like to point out that as of the January 2024, the method described for finding the organization ID for an AGOL organization no longer works. When goes to the endpoint described by following the link: "https://<orgName>.maps.arcgis.com/sharing/rest/portals/self?f=json&token=" there is no entry or line for "org.id" or "user.orgId". 

The organization ID is not shared at this endpoint. 

0 Kudos
AndrewCoutts
New Contributor

Hey Ian, did you find out which endpoint returns this now? This seems to be the most recent comment on this topic.

0 Kudos
AndrewCoutts
New Contributor

I'm not sure how to edit my post, but just figured it out. The endpoint does return that information, once you post to that endpoint with the appropriate token. Without the token it there is a chunk of returned information that is missing.

Tested Feb 2024

0 Kudos
BrianFlood
Occasional Contributor
hi all

does "access: org" (or the orgId: you mentioned) work for any of your REST calls? It works from the ArcGIS.com UI but I can't get it to work from the API using OAuth access tokens.

thanks
brian
0 Kudos
AnttiKajanus1
Occasional Contributor III
Hi,

I haven't tested that with OAuth2 and I don't have any implementation of that in hand.

I created fast test with token based authentication in WPF and it returns correct results (1 when not authenticated and 8 when token is added).

  IdentityManager.Current.GenerateCredentialAsync(
                "http://www.arcgis.com/sharing/rest/",
                "xxxx", // here should be your username 
                "xxx", // here should be your password 
                (credential, ex) =>
                    {
                        if (ex != null)
                        {
                            MessageBox.Show(ex.ToString());
                            return;
                        }


                        var portal = new ArcGISPortal();
                        portal.Token = credential.Token;


                        portal.SearchUsersAsync(
                            new SearchParameters() { Limit = 100, QueryString = "orgid:yourid" },
                            (info, exception) =>
                                {
                                    if (info != null)
                                    {
                                        MessageBox.Show(info.Results.Count().ToString());
                                    }
                                });
                    });


            var portal1 = new ArcGISPortal();
            
            portal1.SearchUsersAsync(
                new SearchParameters() { Limit = 100, QueryString = "orgid:yourid" },
                (info, exception) =>
                {
                    if (info != null)
                    {
                        MessageBox.Show(info.Results.Count().ToString());
                    }
                });


and request generated
GET http://www.arcgis.com/sharing/rest/community/users?num=100&q=orgid%<idhere>&f=json& HTTP/1.1

GET http://www.arcgis.com/sharing/rest/community/users?num=100&q=orgid%<idhere>&f=json&token=yNMOPUrVkzMRwYdNWYoYY4I0sOFHKh4IRFwFM6Lc8NFJYXqrg-lmgpwEruT6u68e_VGWsAykDCcUgUxsOxgGHXLzQ5aZ56k-98acP8bSX2UQeYWesde4a-HXL_gIml2B& HTTP/1.1


I am also curious if there are issues with OAuth based solutions so please updates if you find something to that.
0 Kudos
BrianFlood
Occasional Contributor
hi

yea, the standard user login tokens seem to work fine but the OAuth tokens don't seem to work the same. "access: org" or "orgId: XXX" do not return the same results as the login token, which is quite odd

no answers, still trying to get esri to confirm/deny the issue

cheers
brian
0 Kudos