Search code examples
box-apiboxboxapiv2

How to move a Box user's file to an admin Folder?


I am trying to move a Box user's file to a folder in admin account. The documentation at https://developers.box.com/docs/#files-update-a-files-information tells how to move the file within an account, but not across users. How do I do it using the API?


Solution

  • To move content between one user and another, both users must be able to have access to the content. You can do that in a 3 step process.

    Assuming you are logged in as an enterprise-admin, have granted that admin permission to see user's content, and have created an API key with scope to do administrative functions.

    1. Collaborate the admin into the users's folder as a co-owner, or at least an editor.
    2. Move the document (or folders) into some admin-owned folder that the user can't see.
    3. Un-Collaborate the admin from the user's folder.
    4. (Optional) - add the user in as a view-only collaborator on the new folder, so they can see that the Admin took their document.

    5. POST ./collaborations with body {"item":{"id", "<folder id>", "type":"folder"}, "accessible_by":{"id": "<user_id>", "type": "user"}, "role":"editor"}

    6. PUT /files/<id> with body {"parent", {"type":"folder", "id":"<new folder id>"}}
    7. DELETE ./collaborations/<id>