提问人:Bennimi 提问时间:10/23/2023 最后编辑:Bennimi 更新时间:10/23/2023 访问量:75
使用 Azure DevOps WorkItemTracking sendmail 返回 411
Use the Azure DevOps WorkItemTracking sendmail returns 411
问:
当我尝试卷曲 Azure 的 SendMail 终结点时,我收到以下错误。该文档并没有真正的帮助。我做错了什么?
endpoint=https://dev.azure.com/myorg/myproject/_apis/wit/sendmail?api-version=7.1-preview.1
body='{
"message": {
"body": "Test Body",
"cc": {},
"to": {
"tfsIds": ["my-tfsIds-id"]
},
"replyTo": {},
"subject": "Test Subject"
},
projectId:"my-project-id"
}'
curl -X POST "$endpoint" --data "$body" -H "Authorization: Basic $pat" -H "Content-Type: application/json" -vL
Note: Unnecessary use of -X or --request, POST is already inferred.
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>
PS:我也得到了一个重定向,我真的不明白为什么,但我想这是登录权限?
* Connection #0 to host dev.azure.com left intact
* Issue another request to this URL: 'https://xxxxx.vssps.visualstudio.com/_signin?realm=dev.azure.com&reply_to=https%3A%2F%2Fdev.azure.com%2FMYORG%2FMYPRODJECT%2F_apis%2Fwit%2Fsendmail%3Fapi-version%3D7.1-preview.1&redirect=xxxxxxxxxxxxxxxxx'
* Switch from POST to GET
* Trying xx.xxx.xx.xx:443...
* Connected to xxxxx.vssps.visualstudio.com (xx.xxx.xx.xx:443) port 443 (#1)
更新
通过包含标头,它现在返回 503..Content-Length
不好意思!我们的服务目前不可用。
我们正在努力尽快恢复所有服务。请 请稍后再回来查看。
要查看我们服务的最新状态,请访问我们的支持 页。
答:
0赞
Ikhtesam Afrin
10/23/2023
#1
我已使用以下PowerShell脚本按预期调用并获取电子邮件。POST https://dev.azure.com/{organization}/{project}/_apis/wit/sendmail?api-version=7.1-preview.1
$myorg="organization_name"
$myproject="project_name"
$pat="Base64 converted PAT"
$endpoint="https://dev.azure.com/$myorg/$myproject/_apis/wit/sendmail?api-version=7.1-preview.1"
$body='{
"ids": [work item id],
"message": {
"body": "Test Body",
"cc": {},
"to": {
"tfIds": ["your tfId"]
},
"replyTo": {},
"subject": "Test Subject"
}
}'
Invoke-RestMethod -Uri $endpoint -Method POST -Body $body -Headers @{Authorization=("Basic $pat")} -ContentType "application/json"
请添加工作项 ID 的 ID,
并在请求正文中更正 tfId
。
电子邮件-
参考资料:- Azure DevOps SendMail Rest API 返回 204,但不发送电子邮件 - 堆栈溢出
评论
0赞
Bennimi
10/23/2023
不幸的是,这对我不起作用。我认为我的组织不允许使用 API...
0赞
Ikhtesam Afrin
10/23/2023
@Bennimi你得到什么错误?请检查您是否已将此角色授予 PAT
0赞
Bennimi
10/23/2023
这很奇怪,我需要遵循重定向,否则什么也没发生,那么我必须包含内容长度,否则我会得到提到的 411。包含两者后,我现在会得到服务超时。我认为问题不在于内容正文。(我更新了我的答案)。
0赞
Ikhtesam Afrin
10/23/2023
你有没有试过没有内容长度?
1赞
Bennimi
10/23/2023
不,它也不起作用。是的,可以,感谢您的帮助!
评论