05-28-2018 05:06 PM
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
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.
05-29-2018 03:23 AM
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.
05-29-2018 03:23 AM
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.
03-23-2022 05:36 PM
It's creazy to traverse up the chain of parents
Now in 2022 is there another way to get the parent site without traversing the parent chain ?
Thanks you in advance.
03-24-2022 02:51 AM
You may use the regular node API with the include=path parameter
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" ] } ] }
05-29-2018 09:08 AM
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);
Explore our Alfresco products with the links below. Use labels to filter content by product module.