To get a list of the targets (peer associations) we created make a GET call to the following URL: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{sourceId}/targets
The {sourceId} represents the node identifier for the node we want to list peer associations for. To list associations for our newly created gadget with the node id 74351ea7-8c72-44e4-829c-7d606a8682c7 make a call as follows:
$ curl -X GET -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/74351ea7-8c72-44e4-829c-7d606a8682c7/targets | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1226 0 1226 0 0 15325 0 --:--:-- --:--:-- --:--:-- 15325 { "list": { "pagination": { "count": 2, "hasMoreItems": false, "totalItems": 2, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-10-21T09:42:48.727+0000", "isFolder": false, "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T09:42:48.727+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "gadget-review.txt", "association": { "assocType": "fdk:reviews" }, "id": "581baebd-3814-4cd0-884a-3179f2dac0ac", "nodeType": "cm:content", "content": { "mimeType": "text/plain", "mimeTypeName": "Plain Text", "sizeInBytes": 47, "encoding": "ISO-8859-1" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3" } }, { "entry": { "createdAt": "2019-10-21T10:01:55.279+0000", "isFolder": false, "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T10:01:55.279+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "Cool Gadgets Inc", "association": { "assocType": "fdk:company" }, "id": "5bae662a-b450-49c0-8f40-8ba2046aa423", "nodeType": "fdk:company", "content": { "mimeType": "application/octet-stream", "mimeTypeName": "Binary File (Octet Stream)", "sizeInBytes": 0, "encoding": "UTF-8" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3" } } ] } }
We can see here that there exists two peer associations for the gadget node, one for the review and one for the company. If you remove the gadget node these target nodes will not be deleted automatically.
We can also combine some of the techniques we’ve learned in other sections of the ReST API User Guide and just request the fdk:reviews association and show the path and properties of the target node using the following GET call:
http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{sourceId}/targets?include=properties,path&where=(assocType='{association type}')
To get all the reviews for the gadget make the call as follows:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/74351ea7-8c72-44e4-829c-7d606a8682c7/targets?where=(assocType%3D'fdk%3Areviews')&include=path%2C%20properties' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1064 0 1064 0 0 50666 0 --:--:-- --:--:-- --:--:-- 53200 { "list": { "pagination": { "count": 1, "hasMoreItems": false, "totalItems": 1, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T09:42:48.727+0000", "association": { "assocType": "fdk:reviews" }, "nodeType": "cm:content", "content": { "mimeType": "text/plain", "mimeTypeName": "Plain Text", "sizeInBytes": 47, "encoding": "ISO-8859-1" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3", "createdAt": "2019-10-21T09:42:48.727+0000", "path": { "name": "/Company Home/My Gadgets", "isComplete": true, "elements": [ { "id": "695c2c56-3ba0-4539-b301-12bd9bb47712", "name": "Company Home", "nodeType": "cm:folder", "aspectNames": [ "cm:titled", "cm:auditable", "app:uifacets" ] }, { "id": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3", "name": "My Gadgets", "nodeType": "cm:folder", "aspectNames": [ "cm:auditable" ] } ] }, "isFolder": false, "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "gadget-review.txt", "id": "581baebd-3814-4cd0-884a-3179f2dac0ac", "properties": { "cm:versionLabel": "1.0", "cm:versionType": "MAJOR" } } } ] } }
We can retrieve the list of secondary child associations by using the following GET call: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{sourceId}/secondary-children
Here is how that looks like:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/74351ea7-8c72-44e4-829c-7d606a8682c7/secondary-children' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 671 0 671 0 0 13420 0 --:--:-- --:--:-- --:--:-- 13420 { "list": { "pagination": { "count": 1, "hasMoreItems": false, "totalItems": 1, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-10-21T09:32:53.121+0000", "isFolder": false, "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T10:08:09.614+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "gadget-picture.png", "association": { "isPrimary": false, "assocType": "fdk:images" }, "id": "b8dc45cd-6828-41df-a908-e0fa8dbbd96b", "nodeType": "cm:content", "content": { "mimeType": "image/png", "mimeTypeName": "PNG Image", "sizeInBytes": 42303, "encoding": "UTF-8" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3" } } ] } }
The response is similar to the previous example except we’re seeing the fdk:images child association.
What if we want to go in the other direction and see what links to a particular node, for peer associations we can use the following GET call: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{targetId}/sources
In this case the {targetId} would be the node identifier of the target node in the association. For example, to get anything linking to the gadget review text file (581baebd-3814-4cd0-884a-3179f2dac0ac) use the following GET call:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/581baebd-3814-4cd0-884a-3179f2dac0ac/sources' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 673 0 673 0 0 9219 0 --:--:-- --:--:-- --:--:-- 9219 { "list": { "pagination": { "count": 1, "hasMoreItems": false, "totalItems": 1, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-10-21T10:08:09.561+0000", "isFolder": false, "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T10:08:09.561+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "My Gadget", "association": { "assocType": "fdk:reviews" }, "id": "74351ea7-8c72-44e4-829c-7d606a8682c7", "nodeType": "fdk:gadget", "content": { "mimeType": "application/octet-stream", "mimeTypeName": "Binary File (Octet Stream)", "sizeInBytes": 0, "encoding": "UTF-8" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3" } } ] } }
We should see that the “My Gadget” node is linked to the review text file.
To see parents for child associations we use a GET call to the following URL: http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{childId}/parents
For example, to see the parents of the gadget picture file (b8dc45cd-6828-41df-a908-e0fa8dbbd96b) we uploaded earlier, we should see 2 parents, the “My Gadget” node and the “My Gadgets” folder where the image itself was uploaded:
$ curl -X GET -H 'Accept: application/json' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/b8dc45cd-6828-41df-a908-e0fa8dbbd96b/parents' | jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1139 0 1139 0 0 33500 0 --:--:-- --:--:-- --:--:-- 33500 { "list": { "pagination": { "count": 2, "hasMoreItems": false, "totalItems": 2, "skipCount": 0, "maxItems": 100 }, "entries": [ { "entry": { "createdAt": "2019-10-21T10:08:09.561+0000", "isFolder": false, "isFile": true, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T10:08:09.561+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "My Gadget", "association": { "isPrimary": false, "assocType": "fdk:images" }, "id": "74351ea7-8c72-44e4-829c-7d606a8682c7", "nodeType": "fdk:gadget", "content": { "mimeType": "application/octet-stream", "mimeTypeName": "Binary File (Octet Stream)", "sizeInBytes": 0, "encoding": "UTF-8" }, "parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3" } }, { "entry": { "createdAt": "2019-10-21T09:30:41.096+0000", "isFolder": true, "isFile": false, "createdByUser": { "id": "admin", "displayName": "Administrator" }, "modifiedAt": "2019-10-21T10:08:09.692+0000", "modifiedByUser": { "id": "admin", "displayName": "Administrator" }, "name": "My Gadgets", "association": { "isPrimary": true, "assocType": "cm:contains" }, "id": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3", "nodeType": "cm:folder", "parentId": "695c2c56-3ba0-4539-b301-12bd9bb47712" } } ] } }