How to get site id of a node using REST API ?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

How to get site id of a node using REST API ?

Jump to solution

Hi All,

I would like to get site name / id of a given node id. How can I do that?

I used the below query (/nodes/{nodeId}/parents) but apparently it gives only the immediate parent of the node?

Request

http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/b5c8f4ec-e7e2-4e74-81c...

Response

{
   "list":{
      "pagination":{
         "count":1,
         "hasMoreItems":false,
         "totalItems":1,
         "skipCount":0,
         "maxItems":100
      },
      "entries":[
         {
            "entry":{
               "createdAt":"2018-05-28T17:40:02.421+0000",
               "isFolder":true,
               "isFile":false,
               "createdByUser":{
                  "id":"admin",
                  "displayName":"Administrator"
               },
               "modifiedAt":"2018-05-28T23:55:58.705+0000",
               "modifiedByUser":{
                  "id":"admin",
                  "displayName":"Administrator"
               },
               "name":"MyFolder1",
               "association":{
                  "isPrimary":true,
                  "assocType":"cm:contains"
               },
               "id":"7bd86fea-5477-470f-9d91-2c7937a8936e",
               "nodeType":"cm:folder",
               "parentId":"18f734ac-8e2c-424b-a75c-c19db3ea6d36"
            }
         }
      ]
   }
}

Please let me know

Thank you,

Edit by Axel Faust‌: Use syntax highlighter and formatting to make post easier to read.

1 Solution

Accepted Solutions
Highlighted
Master

Re: How to get site id of a node using REST API ?

Jump to solution

You need to traverse up the chain of parents until you find a node of type st:site. Then use that node's name as the site ID.

View solution in original post

2 Replies
Highlighted
Master

Re: How to get site id of a node using REST API ?

Jump to solution

You need to traverse up the chain of parents until you find a node of type st:site. Then use that node's name as the site ID.

View solution in original post

Highlighted
Professional

Re: How to get site id of a node using REST API ?

Jump to solution

An alternative would be to write a simple web script with a Java controller. The SiteService has a getSite() method that accepts a node reference and returns a SiteInfo object for the site that contains that node.

    /**
     * This method gets the {@link SiteInfo} for the Share Site which contains the given NodeRef.
     * If the given NodeRef is not contained within a Share Site, then <code>null</code> is returned.
     *
     * @param nodeRef   the node whose containing site's info is to be found.
     * @return SiteInfo  site information for the containing site or <code>null</code> if node is not in a site.
     */

    @NotAuditable
    SiteInfo getSite(NodeRef nodeRef);