# Add a composition to a folder via openEHR REST API **Category:** [ITS](https://discourse.openehr.org/c/its/41) **Created:** 2023-08-28 11:18 UTC **Views:** 695 **Replies:** 8 **URL:** https://discourse.openehr.org/t/add-a-composition-to-a-folder-via-openehr-rest-api/4388 --- ## Post #1 by @ian.mcnicoll Sorry I'm being dumb but I can see a way to allocate a composition to a folder in the REST API - help? --- ## Post #2 by @stefanspiska Since the Directory endpoint always updates the whole structure you simple put it in the Folder structure which represents the directory . So call https://specifications.openehr.org/releases/ITS-REST/latest/ehr.html#tag/DIRECTORY/operation/directory_update with ``` { "_type": "FOLDER", "name": { "_type": "DV_TEXT", "value": "root" }, "archetype_node_id": "openEHR-EHR-FOLDER.generic.v1", "folders": [ { "_type": "FOLDER", "name": { "_type": "DV_TEXT", "value": "history" }, "archetype_node_id": "openEHR-EHR-FOLDER.generic.v1", "folders": [ { "_type": "FOLDER", "name": { "_type": "DV_TEXT", "value": "family" }, "archetype_node_id": "openEHR-EHR-FOLDER.generic.v1", "items": [ { "id": { "_type": "HIER_OBJECT_ID", "value": "d936409e-901f-4994-8d33-ed104d46015b" }, "namespace": "my.system.id", "type": "VERSIONED_COMPOSITION" } ] } ] } ] } ``` see also https://github.com/ehrbase/integration-tests/blob/main/tests/robot/DIRECTORY_TESTS/UPDATE_DIRECTORY/H.1__EHR_with_directory.robot --- ## Post #3 by @stefanspiska so 1. Create Directory if not exists. 2. get old Directory from openehr server 3. edit the json representing the Directory 4. Update the whole structure. The ehrbase sdk has some tools to help with that https://github.com/ehrbase/openEHR_SDK/blob/develop/client/src/test/java/org/ehrbase/openehr/sdk/client/openehrclient/defaultrestclient/DefaultDirectoryCrudEndpointTestIT.java --- ## Post #4 by @joostholslag [quote="stefanspiska, post:2, topic:4388"] Since the Directory endpoint always updates the whole structure [/quote] SEC might want to have a look at adding an endpoint that edits specific FOLDERs. Similar to what we do with compositions. Especially in complex systems with authorisations per FOLDER this is an issue. But it’s also error pronken I think to let every client always change the entire directory. --- ## Post #5 by @sebastian.iancu Yes you are right, that's on the REST "roadmap" actually, and requires RM 1.1.0+. --- ## Post #6 by @pablo That has been already discussed. We proposed an API for that, I think there is a ticket on the openEHR JIRA. --- ## Post #7 by @linforest Might my question [*How to retrieve and update a subfolder in the FOLDER Structure?*](https://discourse.openehr.org/t/how-to-retrieve-and-update-a-subfolder-in-the-folder-structure/5691) be related to this? --- ## Post #8 by @pablo Related JIRA ticket https://openehr.atlassian.net/issues/SPECPR-411?jql=text%20~%20%22folder%2A%22%20AND%20project%20%3D%20SPECPR --- ## Post #9 by @linforest Thanks a lot, @pablo. --- **Canonical:** https://discourse.openehr.org/t/add-a-composition-to-a-folder-via-openehr-rest-api/4388 **Original content:** https://discourse.openehr.org/t/add-a-composition-to-a-folder-via-openehr-rest-api/4388