Last active
September 20, 2017 20:02
-
-
Save jdmills-edu/c2eca71dcd11ec7e38fb72493d143829 to your computer and use it in GitHub Desktop.
A PowerShell script to create a Dropbox Paper document from markdown, impersonating a Dropbox Business/Education/Enterprise Team Member.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory=$true)][String]$markdownFilePath, | |
[String]$parentFolderID | |
) | |
$token = 'Bearer xxxyourapptokenherexxx' | |
#You'll need to use the Dropbox Business API to get the Team Member's ID. | |
$teamMemberID = "xxxxxx" | |
$authHeader = 'Authorization: '+$token | |
#This is Dropbox's way of granting your Team Member File Access app permission to run as a given user with user API endpoints. | |
$impersonationHeader = 'Dropbox-API-Select-User: '+$teamMemberID | |
#We have to escape quotation marks in HTTP headers when using curl.exe instead of Invoke-RestMethod | |
if($parentFolderID){ | |
$argsHeader = 'Dropbox-API-Arg: {\"import_format\": \"markdown\"}, \"parent_folder_id\": "'+$parentFolderID+'"' | |
} | |
else{ | |
$argsHeader = 'Dropbox-API-Arg: {\"import_format\": \"markdown\"}' | |
} | |
$result = &C:\path\to\curl.exe -X POST https://api.dropboxapi.com/2/paper/docs/create ` | |
--header $authHeader ` | |
--header $impersonationHeader ` | |
--header $argsHeader ` | |
--header 'Content-Type: application/octet-stream' ` | |
--data-binary $dataHeader | ConvertFrom-Json | |
return $result |
You can use this other script to grab a Dropbox user's team member ID by passing it the user's email address.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this script in an attempt to use the Dropbox Paper API to automatically generate rapid response checklists/documents for phishing attacks, compromised accounts, and other security incidents. You can easily generate the markdown ".md" file by writing a template document in Dropbox Paper, downloading it in markdown format from the web interface, then adding placeholders/variables within the resulting document. Next, tell your script to swap out the placeholders with real data, then upload the new .md file using this PowerShell script.