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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use this other script to grab a Dropbox user's team member ID by passing it the user's email address.