azure-devops - 从 Postman 在 Azure Devops 中创建工作项
问题描述
我们希望将所有项目从 Jira 迁移到 Azure Devops,其中之一就是我们的帮助台功能。
我的任务是移植我们当前有关票证的解决方案:我们有一个 Laravel 项目正在运行,它检查某些电子邮件地址是否有新的帮助请求。当收到新电子邮件时,它会向我们的 Slack 发送通知,其中一名团队成员确认并选择在 Jira 中创建票证的位置。然后它根据 Slack 中的选择在 Jira 中创建一个带有 api-call 的新票证。
我已经找到并试用了 Azure Devops API,可以列出项目并获取工作项等。但我不能通过调用 POST 一个新的工作项
http://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$task?api-version=6.1-preview.3&bypassRules=true
使用这样的 JSON 正文:
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Test of REST functionality"
},
{
"op": "add",
"path": "/fields/System.State",
"from": null,
"value": "New"
}
]
我收到这样的 JSON 响应
{
"fields": {
"System.WorkItemType": "Task",
"System.AreaPath": "xxxxx",
"System.TeamProject": "xxxx",
"System.IterationPath": "xxxx",
"System.State": "New",
"System.Reason": "New",
"Microsoft.VSTS.Common.StateChangeDate": "1753-01-01T00:00:00Z",
"System.ChangedBy": {
"displayName": "xxxx",
"url": "xxxx",
"_links": {
"avatar": {
"href": "xxxx"
}
},
"id": "xxxx",
"uniqueName": "xxxx",
"imageUrl": "xxxx",
"descriptor": "xxxx"
},
"System.CreatedBy": {
"displayName": "xxxx",
"url": "xxxx",
"_links": {
"avatar": {
"href": "xxxx"
}
},
"id": "xxxx",
"uniqueName": "xxxx",
"imageUrl": "xxxx",
"descriptor": "xxxx"
},
"Microsoft.VSTS.Common.Priority": 2
},
"_links": {
"workItemType": {
"href": "https://dev.azure.com/{organization}/{project}/_apis/wit/workItemTypes/Task"
},
"fields": {
"href": "https://dev.azure.com/{organization}/{project}/_apis/wit/fields"
}
},
"url": "https://dev.azure.com/{organization}/{project}/_apis/wit/workItems"
}
最后一个 url 将我指向一个带有包含此消息的 JSON 对象的页面:
No HTTP resource was found that matches the request URI 'https://dev.azure.com/{project}/_apis/wit/workItems'
并且不会创建新任务。
我从查阅文档开始。
我尝试使用有关工作项的几种不同权限组合来编辑和重新生成我的个人访问令牌。我试过给 PAT 完全访问权限。
我尝试调用不同版本的 API。
我尝试添加除标题和状态之外的字段,这些字段是按要求列出的,最后将 bypassRules 设置为 true。
谷歌和 /r/azuredevops subreddit 没有返回任何有效的结果。
谁能指出我应该去哪里,或者我错过了什么?提前致谢 :-)
编辑:我在发帖。
编辑解决方案:
我觉得自己好傻。在 Postman 中发布时,我使用 http:// 而不是 https:// 使用 https:// 解决了这个问题。
解决方案
请检查图片,根据请求正文,您似乎正在使用 REST API获取工作项类型定义而不是创建工作项
如果方法是GET,它将获取工作项类型。
请求正文:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitemtypes/{type}?api-version=6.0
像这样的 JSON 响应:
{
"fields": {
.....
},
"_links": {
.....
},
"url": "https://dev.azure.com/{organization}/{project}/_apis/wit/workItems"
}
邮递员结果:
如果我们需要创建工作项,我们需要将方法更改为POST
请求网址:
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=6.0
请求正文:
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Test of REST functionality"
},
{
"op": "add",
"path": "/fields/System.State",
"from": null,
"value": "New"
}
]
像这样的 JSON 响应:
{
"id": {Work Item ID},
"rev": 1,
"fields": {
...
},
"_links": {
...
},
"url": "https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{Work Item ID}"
}
邮递员结果:
Azure DevOps 服务结果:
更新1
但我想知道你的网址中有什么
我的网址是
https://dev.azure.com/{Org name}/{Project name}/_apis/wit/workitems/$task?api-version=6.0
你有 12 个标题,我有 9 个,而且我的 url 似乎比你的长
- 在 postman 中新建一个请求页面,默认 Header 为 7,输入 Request URL,会添加 header
Cookie
,现在 Header 为 8。
- 将方法从 GET 更改为 POST,它将添加标题
Content-Length
,现在标题为 9。
- 单击Body选项卡- >选择raw并将内容类型更改为JSON以添加请求正文,它将添加标头
Content-Type
,现在标头为 10
- 单击授权选项卡->选择基本身份验证并输入 PAT 令牌作为密码,它将添加标题
Authorization
,现在标题为 11。
- 现在,当我们单击发送按钮时,我们将收到错误消息
The request indicated a Content-Type of \"application/json\" for method type \"POST\" which is not supported. Valid content types for this method are: application/json-patch+json.
- 点击 Header 选项卡,默认值为
Content-Type
,application/json
我们需要禁用它并添加新的 headerContent-Type
并将值设置为application/json-patch+json
,现在 Header 为 12
- 单击按钮发送,响应代码为 200
推荐阅读
- php - How to disable delete option for a specific page in Wordpress admin?
- mongodb - 减少特定文档上第一个找到的子元素的属性
- python - 根据python中的值范围将csv文件拆分为各个列
- ios - 当点击手势执行时,带有uitextfield的逐字母动画正在同时执行
- c# - 如果输入无效数据如何重复代码
- javascript - 如何在 reactjs 列表视图中动态显示对象属性
- html - 是否有使用 XPath 扩展 XML 文档模板的工具?
- sql - 如何从 PostgreSQL 的另一个表中插入对 UUID 的引用?
- javascript - 仅针对大数据查找数组中最大数的总数失败
- ios - 触摸滚动视图的幻灯片时暂停计时器?