Skip to content

Instantly share code, notes, and snippets.

@dkeightley
Created August 5, 2020 02:50
Show Gist options
  • Save dkeightley/1a499a1f2b2c18108bf38a7ad1935875 to your computer and use it in GitHub Desktop.
Save dkeightley/1a499a1f2b2c18108bf38a7ad1935875 to your computer and use it in GitHub Desktop.
Function to create box folder and file requests
function box-request()
{
_BEARER_TOKEN="<box app token>"
_FOLDER_NAME=$1
echo -n "Creating ${_FOLDER_NAME}"
_FOLDER_ID=$(curl -sX POST https://api.box.com/2.0/folders \
-H "Authorization: Bearer ${_BEARER_TOKEN}" \
-H 'Content-Type: application/json' \
-d '{
"name": "'${_FOLDER_NAME}'",
"parent": {
"id": "109957074997"
}
}' | jq -r '.id')
echo "... done"
echo -n "Creating file request"
_FOLDER_REQUEST_URL=$(curl -s "https://app.box.com/app-api/file-request-web/file-request?folderId=${_FOLDER_ID}" \
-H "Authorization: Bearer ${_BEARER_TOKEN}" \
-H 'Content-Type: application/json' | jq -r '.url')
echo "... done"
echo "You can access the box folder here: https://app.box.com/folder/${_FOLDER_ID}"
echo "File request URL: https://app.box.com${_FOLDER_REQUEST_URL}"
echo "https://app.box.com${_FOLDER_REQUEST_URL}" | pbcopy
echo "File request URL copied to clipboard!"
}
@dkeightley
Copy link
Author

Setup:

  1. visit https://app.box.com/developers/console/newapp and generate a new custom app token, choose OAuth 2.0 with JWT
  2. copy the bearer token to the _BEARER_TOKEN variable
  3. copy this to your .bashrc or .zshrc
  4. source ~/.zshrc etc
  5. box-request <folder>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment