GuidesCollectionsRemove Item from Collection
Edit this page

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.

The only collection that is available via the API is the "Favorites" collection and therefore to remove an item from this collection can be achieved by passing the API an empty array of collections.

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.

cURL
curl -X PUT https://api.box.com/2.0/folders/12345 \
     -H 'Authorization: Bearer <ACCESS_TOKEN>'
     -H 'Content-Type: application/json" '
     -d '{
       "collections": []
     }'
Node
client.folders.removeFromCollection('87263', '235747', callback);

To add a web link to a collection, call the PUT /web_links/:id API and pass an empty array of collection IDs.

cURL
curl -X PUT https://api.box.com/2.0/web_links/12345 \
     -H 'Authorization: Bearer <ACCESS_TOKEN>'
     -H 'Content-Type: application/json" '
     -d '{
       "collections": []
     }'
Node
client.weblinks.removeFromCollection('87263', '235747', callback);