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

cancel
Showing results for 
Search instead for 
Did you mean: 
mikeitexpert
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
afaust
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

4 Replies
afaust
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.

jpotts
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);
soungalo
Active Member

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

Jump to solution

It's creazy to traverse up the chain of parents Smiley Happy

Now in 2022 is there another way to get the parent site without traversing the parent chain ? 

Thanks you in advance.

angelborroy
Alfresco Employee

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

Jump to solution

You may use the regular node API with the include=path parameter

http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/1a0b110f-1e09-4ca2-b36...

The response will include the Site and all the other parent folders

"path": {
            "name": "/Company Home/Sites/swsdp/documentLibrary/Agency Files/Contracts",
            "isComplete": true,
            "elements": [
                {
                    "id": "1810057d-ad92-4adf-b770-2916c56251f3",
                    "name": "Company Home",
                    "nodeType": "cm:folder",
                    "aspectNames": [
                        "cm:titled",
                        "cm:auditable",
                        "app:uifacets"
                    ]
                },
                {
                    "id": "9d550dea-d02f-450a-8e30-c05c091e7272",
                    "name": "Sites",
                    "nodeType": "st:sites",
                    "aspectNames": [
                        "cm:titled",
                        "cm:auditable",
                        "app:uifacets"
                    ]
                },
                {
                    "id": "b4cff62a-664d-4d45-9302-98723eac1319",
                    "name": "swsdp",
                    "nodeType": "st:site",
                    "aspectNames": [
                        "cm:tagscope",
                        "cm:ownable",
                        "cm:titled",
                        "cm:auditable"
                    ]
                },
                {
                    "id": "8f2105b4-daaf-4874-9e8a-2152569d109b",
                    "name": "documentLibrary",
                    "nodeType": "cm:folder",
                    "aspectNames": [
                        "cm:tagscope",
                        "st:siteContainer",
                        "cm:titled",
                        "cm:ownable",
                        "cm:auditable"
                    ]
                },
                {
                    "id": "8bb36efb-c26d-4d2b-9199-ab6922f53c28",
                    "name": "Agency Files",
                    "nodeType": "cm:folder",
                    "aspectNames": [
                        "cm:titled",
                        "cm:ownable",
                        "cm:auditable",
                        "cm:taggable"
                    ]
                },
                {
                    "id": "e0856836-ed5e-4eee-b8e5-bd7e8fb9384c",
                    "name": "Contracts",
                    "nodeType": "cm:folder",
                    "aspectNames": [
                        "cm:titled",
                        "cm:ownable",
                        "cm:auditable"
                    ]
                }
            ]
        }
Hyland Developer Evangelist