Box CLI - use box folders:get command
AnsweredHi, I'm trying to generate a list of folders a particular user has access to. None of our users are owners of folders, just editors. So I tried using
box folders:get 0 --as-user
This generates a list of folders in JSON the user has access to in our tenet. But exporting the data has been the issue. When I try to add the "--save" command, the export is a single row of data that doesn't match the previously run command. I'm using the --save option because I'd like to output as a csv.
In a previous version of Box CLI (1.6?) I was able to generate a report that matched the JSON export. That command was
box folders list-items 0 --as-user --save --save-to-file-path C:\exceloutput
Any help will be appreciated!
-
I'm not sure I understand exactly what problem you're seeing; would you mind providing a bit more information so we can try and troubleshoot?
First, exactly what command are you running with the v2 CLI to write the output to file? Next, it would be really helpful if you could provide redacted/sample versions of the output you're seeing and the output you expect to see so I can make sure I know precisely what you're looking for. Thanks!
-
Sure no problem. I think the easiest way to see what I'm doing is to follow my steps. I start by running this command
box folders:get 0 --as-user
That returns a JSON response that lists every folder at the root level for that user.
So I decided that I'd like to export that response into something more palatable, like a CSV file. So I run this command next.
box folders:get 0 --as-user --save
The export CSV file that comes back is two rows that don't seem to have anything to do with the response from the first command. I was assuming that adding the "--save" command would provide the same report but exported as a CSV.
Here is the CSV report with the two rows of info.
type id name description size path_collection.total_count path_collection.entries created_by.type created_by.id created_by.name created_by.login modified_by.type modified_by.id modified_by.name modified_by.login owned_by.type owned_by.id owned_by.name owned_by.login item_status item_collection.total_count item_collection.entries item_collection.offset item_collection.limit item_collection.order folder 0 All Files 382530 0 Array user user ID redacted Name redacted Email redacted user ID redacted Name redacted Email redacted active 83 Array 0 100 Array Does that make more sense?
-
Ah, I think I see what the issue is. You're using the box folders:get command, which is made for retrieving information about a single folder. The folder object includes an item_collection field, which displays a preview of the items in a folder — just the first 100 of them. This is probably what you're seeing in the JSON output. However, that sort of nested array of objects would be very difficult to represent directly in a CSV format, so we simply replace it with Array, which you can see under the item_collection.entries key in the CSV output you posted. If you want to get the full list of items in a folder, not just a preview of the first 100, you'll want to use the box folders:items command instead; that should allow you to output the CSV the way you want it. Could you give that a try and let me know if it works for you?
Please sign in to leave a comment.
Comments
4 comments