创建新用户的代码:
a.tar.gz
a
b.tar.gz
b
script.sh
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
输出:
Invoke-RestMethod:远程服务器返回错误:(400)错误的请求。
任何人,请告诉我解决方法。我尝试使用相同的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)
}
来访问端点“ team / members / list”来获取用户列表,并且可以正常工作。
我对Dropbox API完全陌生,因此我的代码是从Google借来的,而在使用PowerShell时,我尝试使用许多不同的代码进行修补,但均无济于事。
答案 0 :(得分:0)
所有其他方法均失败时,RTFM,其参数为:
{
"new_members": [
{
"member_email": "tom.s@company.com",
"member_given_name": "Tom",
"member_surname": "Silverstone",
"member_external_id": "company_id:342432",
"send_welcome_email": true,
"role": "member_only"
}
],
"force_async": false
}
尝试从.tag
定义中删除role
并将"true"
替换为$true
$Body = @{
"new_members" = @(@{
"member_email" = $email
"member_given_name" = $FirstName
"member_surname" = $LastName
"send_welcome_email" = $true
"role" = "member_only"
})
}