Add Item to Collection

Guides Collections Add Item to Collection
Edit this page

Add Item to Collection

To add an item to a collection, call the PUT endpoint for that specific type of item and pass along a list of collection IDs.

The only collection that is available via the API is the "Favorites" collection. The ID of this collection is different for every user.

Add file to collection

To add a file to a collection, call the PUT /files/:id API and pass along a list 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": [
          {
            "id": "123"
          }
       ]
     }'
Java
BoxCollection favorites = null;
for (BoxCollection.Info info : BoxCollection.getAllCollections(api)) {
    if (info.getCollectionType().equals("favorites")) {
        favorites = info.getResource();
        break;
    }
}
BoxFile file = new BoxFile(api, "id");
file.setCollections(favorites);
Python
collection = client.collection(collection_id='12345')
updated_file = client.file(file_id='11111').add_to_collection(collection)
print(f'File "{updated_file.name}" added to collection!')
.NET
// Put file 11111 into collection 22222
BoxCollectionsRequest requestParams = new BoxCollectionsRequest()
{
    Collections = new List<BoxRequestEntity>()
    {
        new BoxRequestEntity()
        {
            Id = "22222"
        }
    };
};
BoxFile file = await client.CollectionsManager.CreateOrDeleteCollectionsForFileAsync(fileId: "11111", requestParams);
Node
client.files.addToCollection('87263', '235747', callback);
iOS
client.files.addToFavorites(fileId: "11111") { (result: Result<Void, BoxSDKError>) in
    guard case .success = result else {
        print("Error adding file to favorites")
        return
    }

    print("File added to favorites")
}

Add folder to collection

To add a folder to a collection, call the PUT /folders/:id API and pass along a list 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": [
          {
            "id": "123"
          }
       ]
     }'
Node
client.folders.addToCollection('87263', '235747', callback);

To add a web link to a collection, call the PUT /web_links/:id API and pass along a list 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": [
          {
            "id": "123"
          }
       ]
     }'
Node
client.weblinks.addToCollection('87263', '235747', callback);