Building Commands and Help Feature

Building Commands and Help Feature

A full list of CLI commands can be found in the GitHub repository.

If you do not see a command for an endpoint you need, you can build a custom request.

Use repository documentation in conjunction with reference documentation to see information the help command does not provide. This includes restrictions, token permission requirements, fields, etc.

Creating a folder with help

Every CLI command begins with box. Add the option --help to any command for help building it. For example, executing box --help will bring you to a list of all possible object commands. Options are discussed more in step 4.

Help

Then, for example, use the folder object and execute the command box folders --help. This provides a list of all eligible actions for this object.

Help

Discover the required arguments for creating a folder: box folders:create --help

Help

Execute the command box folders:create 0 "My CLI Folder" and note the folder ID returned in the response.

The root level of the folder tree, the All Files page, is always represented by folder ID 0.

Log into your Box account. Can you see this folder in your folder tree?

You cannot see this folder in your own Box account because you do not own, nor are you collaborated in on the folder. You are executing commands as the Service Account and therefore the created folder lives in the Service Account's folder tree rather than your own.

Now, execute the command: box folders:collaborations:add folder_id_created_above --role=editor --user-id=YOUR_USER_ID

To find your user ID, go to your All Files page and click the circle in the top right-hand corner. Select Account Settings from the dropdown. Your user ID is listed as the Account ID under the Account tab.

Return to your All Files page. Can you see the folder now?

The second command used the Service Account, which owns the folder, to add your user as an Editor-level collaborator on the folder. This surfaces the folder in your own folder tree.

Summary

  • You used the help feature to create a folder
  • You added a collaboration to the created folder and viewed it in Box