【发布时间】:2019-10-25 19:03:16
【问题描述】:
我明白这个问题已被多次询问和回答,但我遇到了一个我在论坛上没有看到的错误,我希望有人可能知道我做错了什么。
那么,我在做什么?我正在使用 Expensify API 来自动配置新员工。我已经有一个 2,000 行的新员工脚本,我只是想向其中添加更多 SaaS 应用程序,所以我必须做...更少。
cURL 请求应该如下所示:
curl -X POST 'https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations' \
-H 'Expect:' \
-F 'requestJobDescription={
"type": "update",
"credentials": {
"partnerUserID": "_REPLACE_",
"partnerUserSecret": "_REPLACE_"
},
"inputSettings": {
"type": "employees",
"policyID":"0123456789ABCDEF",
"fileType": "csv"
}
}' \
-F 'data=@employeeData.csv'
我的脚本是这样的:
$expensify_csv = @(
[pscustomobject]@{
EmployeeEmail = $email
ManagerEmail = $mngr_email
Admin = $expensify_admin
ForwardManagerEmail = $fwd_email
}
) | Export-Csv -Path C:\expensify.csv -NoTypeInformation
$expensify_csv = [IO.File]::ReadAllText('C:\expensify.csv');
$json = [ordered]@{
"requestJobDescription" = @{
"type" = "update";
"credentials" = @{
"partnerUserID" = $expensify_id;
"partnerUserSecret" = $expensify_secret;
}
"inputSettings" = @{
"type" = "employees";
"policyID" = "F9CC59BCD4521BB2";
"fileType" = "csv";
}
};
"data" = $expensify_csv
} | ConvertTo-Json -Depth 10
Write-Host $json
$check = Invoke-RestMethod `
-Method Post `
-Uri $expensify_url `
-Body $json `
-ContentType multipart/form-data `
Write-Host $check
exit
以及正在返回的错误:
Invoke-RestMethod :
Error
body{
font-family: Arial;
}
pre{
padding: 5px;
background-color: #ddd;
border-top: 2px solid #999;
}
An error occurred
Internal Server Error
这个错误似乎与 CSS 有关?不过我不知道。很奇怪。我已经与这个 API 斗争了一段时间,如果有任何反馈,我将不胜感激!
【问题讨论】:
-
您正在尝试发送 json... 但您发送的内容类型不匹配。
标签: powershell rest api powershell-5.0