cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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

Re: Create new Dropbox user using Powershell

Marcusyoung7962
Explorer | Level 3
Wyd

Re: Create new Dropbox user using Powershell

AlokSan
New member | Level 2

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

Re: Create new Dropbox user using Powershell

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.

Re: Create new Dropbox user using Powershell

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?

Re: Create new Dropbox user using Powershell

Greg-DB
Dropboxer

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. 

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

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