コメント

5件のコメント

  • whiggs12

    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?

    0
    コメントアクション Permalink
  • Murtza

     For your first question, if you add "--json" to your request it will output all the results at once. For your second question, I'm still researching this and I'll update this thread once I find the answer. 

    0
    コメントアクション Permalink
  • amsxbg

    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.

    0
    コメントアクション Permalink
  • whiggs12

    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?2017-11-02 12_50_47-Administrator_ Windows PowerShell ISE.png

    0
    コメントアクション Permalink
  • amgrobelny

    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-Json

    echo $parsed.entries

     

    Let me know if that helps!

    0
    コメントアクション Permalink

サインインしてコメントを残してください。