Box command line lists
Is there any way to have the command line utility for box simply return all relevant results when retrieving information instead of having to hold down the enter key? Example command:
box users list
-
Another aspect of the Box command line utility which doesn't make any sense to me. When you want to list events, the available arguments let you specify events created during certain time periods. But when the command returns the list of events, there is no indication in the returned data which tells us when the event occurred. Is this correct or am I doing something wrong?
-
If you print out API response using the --json option, the paging mechanism will be bypassed and all JSON data from the API is printed. Additionally, any fields not sent to the console writer (like dates on the event objects) will be there in the JSON data.
So, using JSON printing will work for both of your questions. You can actually set your default print method for the CLI to JSON by using the command "box configure settings toggle-output-json". After setting that, all printed responses to the console will be the JSON object sent from the API.
-
Thank you for your reply. This does indeed return the full list of users, but not in the way I was hoping... I was hoping that the returned list, since json was specified, that the returned list would be an array of objects and would allow a script to obtain information about each object instance by accessing the object's properties. However, when I run "box users list --json" in a powershell console (because that is the scripting language that I am using) and pipe it to get-member (which displays the methods and properties of items in a variable), the returned list is just an array of strings. Specifically, one line per array index in the returned array. This makes it very difficult to pull any information out of command's returned data. For example, I know that when I run Curl.exe in a powershell, the returned data is an object. In fact, it is almost identical to the returned information you would get by running "invoke-webrequest". Is there any way to get the box cli to return an array of objects rather than array of strings?
-
The JSON returned from the Box API is an object with an "entries" field.
{
"entries": []
}
The "entries" field is an array of all the user objects in the case of "box users list", so the entries field is what you're looking for.
From a cursory Google search, it looks like you can use the cmdlet ConvertFrom-Json (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-5.1) to parse a string of JSON with PowerShell. Full disclosure, I know little to nothing about PowerShell, so i'm not sure if this will work. I tried this simple set of commands and it seemed to work:
$json = box users list --json
$parsed = $json | ConvertFrom-Jsonecho $parsed.entries
Let me know if that helps!
サインインしてコメントを残してください。
コメント
5件のコメント