Add the power of the Box AI API to your custom apps at Content Cloud Summit on May 15

Learn more and register!

Remove Item from Collection

Guides Collections Remove Item from Collection
Edit this page

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 remove a file from a collection, call the PUT /files/:id API and pass an empty array of collection IDs.

cURL
curl -i -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(f'File "{updated_file.name}" removed from collection!')
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 remove a folder from a collection, call the PUT /folders/:id API and pass an empty array of collection IDs.

cURL
curl -i -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 remove a web link from a collection, call the PUT /web_links/:id API and pass an empty array of collection IDs.

cURL
curl -i -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);