DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • 4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment
  • Is Podman a Drop-in Replacement for Docker?
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Using OpenAI Embeddings Search With SingleStoreDB

Trending

  • 4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment
  • Is Podman a Drop-in Replacement for Docker?
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Using OpenAI Embeddings Search With SingleStoreDB
  1. DZone
  2. Data Engineering
  3. Databases
  4. Integrating With Box API: Transferring Box File Ownership While Preserving Version History

Integrating With Box API: Transferring Box File Ownership While Preserving Version History

Explore integrating with Box API and learn how to transfer Box file ownership while preserving version history.

Vinod Chandru user avatar by
Vinod Chandru
·
Mar. 14, 19 · Tutorial
Like (1)
Save
Tweet
Share
13.07K Views

Join the DZone community and get the full member experience.

Join For Free

Data security apps integrate with several different cloud providers via Kloudless, enabling them to offer solutions such as Data Loss Prevention across multiple content repositories without having to learn the ins-and-outs of each one.

Security-oriented apps commonly need to identify malicious or compromised files or objects. For example, by scanning through all content in a cloud storage tenant via admin account privileges. Once identified, the app can then “quarantine” the threat by moving it out of reach to an isolated location. A lot of the time, that secure location is simply within an administrator account in the cloud service itself. This lets the DLP app preserve important information such as the file’s version history, its original creator, links to the file, and more.

However, quarantine functionality isn’t straightforward to implement a lot of the time. Consider Box, for example. The Box API docs make no mention of moving a file across users via an admin account. The straightforward implementation would be to download the file impersonating the user and then upload it to the admin user’s account. This destroys all version history, however.

Fortunately, file collaboration permissions provide a simpler mechanism to achieve this functionality.Image title

Transferring Files via Shared Folders

Shared folders present one solution to preserve file history. First, the developer app impersonates the user whose file needs to be removed and creates a folder (Box docs) to share with the admin:

curl -X POST https://api.box.com/2.0/folders \<br>    -H "Authorization: Bearer ACCESS_TOKEN" \<br>    -H "Box-Notifications: off" -H "As-User: USER_ID" \<br>    -d '{"name":"temp", "parent": {"id": "0"}}'

We use the As-User header to impersonate the user. The Box-Notifications:off header prevents Box from notifying users of this background activity.

The app continues to impersonate the user to make the admin user a co-owner of the new folder (Box docs):

curl -X POST https://api.box.com/2.0/collaborations \<br>    -H "Authorization: Bearer ACCESS_TOKEN" \<br>    -H "Box-Notifications: off" -H "As-User: USER_ID" \<br>    -d '{<br>        "item": {<br>            "id": "FOLDER_ID",<br>            "type": "folder"<br>         },<br>         "accessible_by": {<br>             "id": "USER_ID",<br>             "type": "user"<br>         },<br>         "role": "co-owner"<br>    }'

Note that if the admin user is not set up to automatically accept collaborations, the app must also update the collaboration (Box docs) with {'status': 'accepted'} as the admin to accept the pending collaboration.

The app then moves the file to the shared folder as the user and moves it out of the shared folder as the admin. Here’s the API request to move the file out of the shared folder (Box docs):

curl -X PUST https://api.box.com/2.0/files/FILE_ID \<br>    -H "Authorization: Bearer ACCESS_TOKEN" \<br>    -H "Box-Notifications: off" -H "As-User: ADMIN_USER_ID" \<br>    -d '{"parent": {"id": "FOLDER_ID"}}'

The app then deletes the folder (Box docs) while impersonating the user that created it:

curl https://api.box.com/2.0/folders/FOLDER_ID?recursive=true \<br>    -X DELETE -H "Authorization: Bearer ACCESS_TOKEN" \<br>    -H "Box-Notifications: off" -H "As-User: USER_ID"<br>

The admin user, or any other destination, now has access to the original file.

This approach works with several other cloud storage services as well, such as Dropbox and Google Drive. Some cloud providers may include more straightforward ways to transfer files, such as OneDrive for Business.

API History (command) app

Published at DZone with permission of Vinod Chandru. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • 4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment
  • Is Podman a Drop-in Replacement for Docker?
  • Security Challenges for Microservice Applications in Multi-Cloud Environments
  • Using OpenAI Embeddings Search With SingleStoreDB

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: