Create a Node with Associations Using the FDK Content Model - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Now we’re finally ready to create our gadget node. We can specify the child associations using the secondaryChildren property and the peer associations using the targets property. Use the node IDs for the gadget image, review, and company that we created earlier on. We POST to /nodes/{id}/children as usual:

$ curl -H "Content-Type: application/json" -d '{"relativePath":"My Gadgets","name":"My Gadget","nodeType":"fdk:gadget", "secondaryChildren": [ {"childId":"b8dc45cd-6828-41df-a908-e0fa8dbbd96b","assocType":"fdk:images"}], "targets": [ {"targetId":"581baebd-3814-4cd0-884a-3179f2dac0ac","assocType":"fdk:reviews"},{"targetId":"5bae662a-b450-49c0-8f40-8ba2046aa423","assocType":"fdk:company"}]}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   893    0   549  100   344   3496   2191 --:--:-- --:--:-- --:--:--  5687
{
  "entry": {
    "aspectNames": [
      "cm:auditable"
    ],
    "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",
    "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"
  }
}

Here we are creating a contentless file with three associations. We cannot actually see in the response that these associations have been created. There is an endpoint we can use to return the associations for a node.