Skip to main content

Using the API, is there any way to get download/preview counts when you create a shared link for a folder? I can see counts on the files in the folder through the web interface, but files returned by the api don’t have shared link data which is where the counts would show if the individual files had a shared link. The shared link data related to the folder returned by the api exists, but the download/preview counts are always 0. I wasn’t really expecting them to be anything else, but those are the only counts I can find that have any value at all.



I suppose I can create a shared link of each individual file in addition to the folder, but I was hoping to avoid that.



Thanks!

Hi @Kaya , welcome to the forum!



I’m not really sure I understood your message, can you elaborate on your use case and include some examples?



Consider this shared folder from an external entity:



curl --location 'https://api.box.com/2.0/shared_items' \

--header 'boxapi: shared_link=https://nihcc.app.box.com/v/ChestXray-NIHCC' \

--header 'Authorization: Bearer u1...S' \



results in:



{

"type": "folder",

"id": "36938765345",

"sequence_id": "0",

"etag": "0",

"name": "CXR8",

"created_at": "2017-09-01T11:33:07-07:00",

"modified_at": "2023-09-11T08:31:28-07:00",

"description": "",

"size": 45132995251,

"path_collection": {

"total_count": 0,

"entries": :]

},

"created_by": {

"type": "user",

"id": "1972882659",

"name": "Summers, Ronald (NIH/CC/DRD) )e]",

"login": "RSummers@cc.nih.gov"

},

"modified_by": {

"type": "user",

"id": "1972882659",

"name": "Summers, Ronald (NIH/CC/DRD) )e]",

"login": "RSummers@cc.nih.gov"

},

"trashed_at": null,

"purged_at": null,

"content_created_at": "2017-09-01T11:33:07-07:00",

"content_modified_at": "2023-09-11T08:31:28-07:00",

"owned_by": {

"type": "user",

"id": "1972882659",

"name": "Summers, Ronald (NIH/CC/DRD) )e]",

"login": "RSummers@cc.nih.gov"

},

"shared_link": null,

"folder_upload_email": null,

"parent": null,

"item_status": "active"

}



Now if I get the items for the folder:



curl --location 'https://api.box.com/2.0/folders/36938765345/items' \

--header 'boxapi: shared_link=https://nihcc.app.box.com/v/ChestXray-NIHCC' \

--header 'Authorization: Bearer 7O...DIz' \



It returns:



{

"total_count": 14,

"entries": :

{

"type": "folder",

"id": "37178474737",

"sequence_id": "0",

"etag": "0",

"name": "images"

},

{

"type": "folder",

"id": "174256157515",

"sequence_id": "0",

"etag": "0",

"name": "LongTailCXR"

},

{

"type": "folder",

"id": "223604149466",

"sequence_id": "0",

"etag": "0",

"name": "PruneCXR"

},

{

"type": "file",

"id": "939374043869",

"file_version": {

"type": "file_version",

"id": "1013612179469",

"sha1": "ad168537accf0020f7f6424fe23dad6fb6465a16"

},

"sequence_id": "0",

"etag": "0",

"sha1": "ad168537accf0020f7f6424fe23dad6fb6465a16",

"name": "AAA Job Opportunity!!! Cloud Computing - Masters or PhD Degree.pdf"

},

{

"type": "file",

"id": "1001272740624",

"file_version": {

"type": "file_version",

"id": "1083663545424",

"sha1": "5ca78d5de3012d0d54776a56009661e54772024c"

},

"sequence_id": "2",

"etag": "2",

"sha1": "5ca78d5de3012d0d54776a56009661e54772024c",

"name": "AAA Physician AI Research Opportunity!!!.pdf"

},

{

"type": "file",

"id": "906187165990",

"file_version": {

"type": "file_version",

"id": "1426213127952",

"sha1": "ee9247194f1f49612d7b92cce12b53ed69cd6f2e"

},

"sequence_id": "1",

"etag": "1",

"sha1": "ee9247194f1f49612d7b92cce12b53ed69cd6f2e",

"name": "AAA Postdoctoral Fellowship Opportunity!!! - NIH Medical Image Analysis Postdoc.pdf"

},

{

"type": "file",

"id": "256057377774",

"file_version": {

"type": "file_version",

"id": "269917681326",

"sha1": "51af83f0f9d49dda58c19c31e2037fcdf1c8bc8d"

},

"sequence_id": "0",

"etag": "0",

"sha1": "51af83f0f9d49dda58c19c31e2037fcdf1c8bc8d",

"name": "ARXIV_V5_CHESTXRAY.pdf"

},

{

"type": "file",

"id": "219760940956",

"file_version": {

"type": "file_version",

"id": "232162176668",

"sha1": "c567ceb25277c9883c5a7fe4c2f70c2ef94b02be"

},

"sequence_id": "0",

"etag": "0",

"sha1": "c567ceb25277c9883c5a7fe4c2f70c2ef94b02be",

"name": "BBox_List_2017.csv"

},

{

"type": "file",

"id": "219760887468",

"file_version": {

"type": "file_version",

"id": "693386667425",

"sha1": "c33382a0946e2d1510e1e005ce611f1283f929d8"

},

"sequence_id": "2",

"etag": "2",

"sha1": "c33382a0946e2d1510e1e005ce611f1283f929d8",

"name": "Data_Entry_2017_v2020.csv"

},

{

"type": "file",

"id": "249502714403",

"file_version": {

"type": "file_version",

"id": "269941556695",

"sha1": "67a06ff686169102b3450893244528fefde1bd69"

},

"sequence_id": "2",

"etag": "2",

"sha1": "67a06ff686169102b3450893244528fefde1bd69",

"name": "FAQ_CHESTXRAY.pdf"

},

{

"type": "file",

"id": "249505703122",

"file_version": {

"type": "file_version",

"id": "693387325041",

"sha1": "e126a4c5dd561431212fda11948a85f0f2ce4218"

},

"sequence_id": "4",

"etag": "4",

"sha1": "e126a4c5dd561431212fda11948a85f0f2ce4218",

"name": "LOG_CHESTXRAY.pdf"

},

{

"type": "file",

"id": "220660789610",

"file_version": {

"type": "file_version",

"id": "363934355357",

"sha1": "2a131c90c074ec386597020d4e46d3661a8bc165"

},

"sequence_id": "2",

"etag": "2",

"sha1": "2a131c90c074ec386597020d4e46d3661a8bc165",

"name": "README_CHESTXRAY.pdf"

},

{

"type": "file",

"id": "256055473534",

"file_version": {

"type": "file_version",

"id": "269915769598",

"sha1": "41b85e218abec560a2f5999acbcf333b0f2fa495"

},

"sequence_id": "0",

"etag": "0",

"sha1": "41b85e218abec560a2f5999acbcf333b0f2fa495",

"name": "test_list.txt"

},

{

"type": "file",

"id": "256056636701",

"file_version": {

"type": "file_version",

"id": "269916925277",

"sha1": "e3e1b677c01d28481777f3d84e10fcdaac05694c"

},

"sequence_id": "0",

"etag": "0",

"sha1": "e3e1b677c01d28481777f3d84e10fcdaac05694c",

"name": "train_val_list.txt"

}

],

"offset": 0,

"limit": 100,

"order": :

{

"by": "type",

"direction": "ASC"

},

{

"by": "name",

"direction": "ASC"

}

]

}



With a total count of 14, but these would include files and folders.



Help us understand your use case a bit better.



Best regards


I’m not looking for the number of files. I’m trying to get preview/download counts for the files within a folder that has a shared link. Those counts appear to be properties of the shared link object which are always 0 for the folder’s shared link. The shared link object is null for each file unless they also have a shared link explicitly created for them. Thanks!


I’m so sorry @Kaya , seems I’ve completely missed your point.



Having said that, you are kind of stuck, the only way to get that information using the API is via the shared link it self, when explicitly created.



Not sure what your exact use case is, however, in the administration console there are quite a few reports related with content:





Perhaps you can explore some of them and see if any fits your needs.



Here is some documentation on the admin reports.



Let us know if this helps



Best regards


No problem! I was actually able to find what I needed in the Enterprise Events api. I could count PREVIEW and DOWNLOAD events where the parent id was the folder I had shared. I’ll just need to download/persist the data elsewhere since it says it only tracks on the past year.


Hi @Kaya



Awesome that you found a workaround.



Speaking of persisting the data elsewhere…



If you want you could store those numbers as metadata on the files/folders, not sure if it fits your use case though.



Also not sure how familiar you are with Box metadata, so allow me to share an article around this topic, although not your use case, it does illustrate metadata capabilities.







Let us know if you have an interest in exploring this possibility.



Best regards


Reply