One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
AlokSan
7 years agoNew member | Level 2
Create new Dropbox user using Powershell
Code
--------------------
Function New-DropBoxUser { [CmdletBinding()]Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0)] [string]$FullName) # Split name into username # $FirstName, $LastName = $FullName.split(' ') $UserName = ($FirstName[0]+$LastName).toLower() $email = "$UserName@mycomp.com"
$Body = @{ "new_members" = @(@{ "member_email" = $email; "member_given_name" = $FirstName; "member_surname" = $LastName; "send_welcome_email" = "true"; "role" = @{ ".tag" = "member_only" } }) } Write-Host '' Write-Host 'Creating DropBox User...' ` -ForegroundColor 'Yellow' ` -BackgroundColor 'Black'$AuthToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'$token = "Bearer $AuthToken" $response=Invoke-RestMethod ` -Method Post ` -Uri "https://api.dropboxapi.com/2/team/members/add" ` -Headers @{ Authorization = $token } ` -ContentType "application/json; charset=utf-8" ` -Body (ConvertTo-Json $Body) }
---------------------
Output:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
- Marcusyoung7962Explorer | Level 3Wyd
- AlokSanNew member | Level 2
The code wasn't pasted properly, so i can reckon. :) Any idea what is the issue with the code?
- AlokSanNew member | Level 2
Better, refer to Stack-Overflow - https://stackoverflow.com/questions/52029373/unable-to-get-past-the-400-error
I have posted there too.
- AlokSanNew member | Level 2
Update
---------------------
Found the error, the error is for two lines within the $Body
1. "send_welcome_email"="true";
Error: Error in call to API function "team/members/add": request body: new_members.send_welcome_email: u'true' is not a valid boolean
2. "role" = @{".tag" = "member_only"}
Error: Error in call to API function "team/members/add": request body: new_members.role: unknown tag 'System.Collections.Hashtable'
Hope now someone can help with this, any idea?
- Greg-DB
Dropbox Staff
It looks like you already got help with this on StackOverflow. As you found, whenever an API call fails, you should check the response body itself for a more detailed message.
In this case, the error indicated that there were unexpected values in the request. Specifically, you were passing in incorrect types for the "send_welcome_email" and "role" parameters.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,941 PostsLatest Activity: 2 days ago
If 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!