You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Carpetes
2 years agoNew member | Level 2
Dropbox-API-Arg could not decode input as JSON
#All credit goes to Jackoby, this is me learning powershell by writting and understanding his code myself
function DropBox-Upload {
[CmdletBinding()]
param (
[Parameter (Mandatory = $True, ValueFromPipeline = $True)]
[Alias("f")]
[string]$SourceFilePath
)
$DropBoxAccessToken = "" #THE TOKEN ONLY LASTS UP TO FOUR HOURS! PLEASE REPLACE WHEN USING
$outputfile = Split-Path $SourceFilePath -leaf
$TargetFilePath = "/$outputfile"
$arg = '{"path": "' + $TargetFilePath + '"mode": "add", "autorename": true, "mute": false}'
$auth = "Bearer " + $DropBoxAccessToken
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $auth)
$headers.Add("Dropbox-API-Arg", $arg)
$headers.Add("Content-Type", 'application/octet-stream')
Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers
}
The last line throws an exception, saying the arg is not valid json?
- Greg-DBDropbox Staff
Carpetes As Здравко noted, from your code it does look like you are not building valid JSON. For instance, it looks like you're missing a quote and a comma after the $TargetFilePath in your $arg. Make sure you're building valid JSON when making these calls.
For this reason, we generally suggest using some JSON library to build the JSON for you whenever possible (as that would be less error prone), instead of attempting to build the string in your own code.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 4 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!