Remove Item from Collection
Remove Item from Collection
To remove an item from a collection, call the PUT
endpoint for that specific
type of item and pass along a list of collection IDs that does not include the
ID of the collection that needs to be removed.
Remove file from collection
To add a file to a collection, call the PUT /files/:id
API and pass an empty
array of collection IDs.
cURL
curl -X PUT https://api.box.com/2.0/files/12345 \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
-H 'Content-Type: application/json" '
-d '{
"collections": []
}'
Java
BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.getInfo("collections");
ArrayList<BoxCollection> collections = new ArrayList<BoxCollection>();
for (BoxCollection.Info info : info.getCollections(api)) {
// Include every existing collection except for favorites to remove the file
// from the favorites collection.
if (!info.getCollectionType().equals("favorites")) {
collections.add(info.getResource());
}
}
file.setCollections(collections.toArray());
Python
collection = client.collection(collection_id='12345')
updated_file = client.file(file_id='11111').remove_from_collection(collection)
print('File "{0}" removed from collection!'.format(updated_file.name))
Node
client.files.removeFromCollection('87263', '235747', callback);
iOS
client.files.removeFromFavorites(fileId: "11111") { (result: Result<Void, BoxSDKError>) in
guard case .success = result else {
print("Error removing file from favorites")
return
}
print("File removed from favorites")
}
Remove folder from collection
To add a folder to a collection, call the PUT /folders/:id
API and pass an
empty array of collection IDs.
Remove web link from collection
To add a web link to a collection, call the PUT /web_links/:id
API and pass an
empty array of collection IDs.