cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create new Dropbox user using Powershell

Create new Dropbox user using Powershell

AlokSan
New member | Level 2

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.

5 Replies 5

Marcusyoung7962
Explorer | Level 3
Wyd

AlokSan
New member | Level 2

The code wasn't pasted properly, so i can reckon. 🙂 Any idea what is the issue with the code?

AlokSan
New 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.

AlokSan
New 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. 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    AlokSan New member | Level 2
  • User avatar
    Marcusyoung7962 Explorer | Level 3
What do Dropbox user levels mean?