针对rest-1.v1/Data的GET和POST操作以及VersionOne中类似端点的默认格式是XML。
我可以使用JSON来获取或发布资产的更新吗?
答案 0 :(得分:4)
是的,可以使用JSON,进行一些调整,并且这个警告:此功能未正式记录或支持,因此在新版本中随时都可能发生变化。
要尝试以下示例,请使用admin
/ admin
作为凭据。
有两种方法可以告诉VersionOne向您发回JSON。
accept=application/json
URL参数https://www14.v1host.com/v1sdktesting/rest-1.v1/Data/Issue/79242 接受=应用/ JSON 强>&安培; SEL =名称,说明
URL参数accept=application/json
告诉VersionOne为指定的问题资产的选定Name
和Description
属性发回JSON而不是XML。
Accept: application/json
HTTP标头您还可以使用标准Accept: application/json
标头。您可以在任何VersionOne实例附带的http.html页面上试用:
rest-1.v1/Data/Issue/79242?sel=Name,Description
application/json
GET
按钮此查询的原始HTTP格式应如下所示:
GET /v1sdktesting/rest-1.v1/Data/Issue/79242?sel=Name,Description HTTP/1.1
Host: www14.v1host.com
Connection: keep-alive
Accept: application/json
你应该得到一个结果,如:
200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
VersionOne: Ultimate/16.0.3.233; Scrum
Content-Length: 252
{
"_type": "Asset",
"href": "/v1sdktesting/rest-1.v1/Data/Issue/79242",
"id": "Issue:79242",
"Attributes": {
"Name": {
"_type": "Attribute",
"name": "Name",
"value": "Adam Martin"
},
"Description": {
"_type": "Attribute",
"name": "Description",
"value": "Adam's description"
}
}
}
要使用JSON而不是XML更新Asset的属性,请在HTTP请求中添加Content-Type: application/json
标头,并使用所需的JSON格式。
以下是从上面修改相同资产的示例:
rest-1.v1/Data/Issue/79242?sel=Name,Description
application/json
application/json
{
"Attributes": {
"Description": {
"value": "New value from the internet",
"act": "set"
}
}
}
POST
按钮你应该得到如下结果:
200 OK
Content-Type: application/json; charset=utf-8
VersionOne: Ultimate/16.0.3.233; Scrum
Content-Length: 210
{
"_type": "Asset",
"href": "/v1sdktesting/rest-1.v1/Data/Issue/79242/114699",
"id": "Issue:79242:114699",
"Attributes": {
"Description": {
"_type": "Attribute",
"name": "Description",
"value": "New value from the internet"
}
}
}
如果安装了cURL,可以使用以下命令对其进行测试:
curl -i -X POST \
-H "Authorization:Basic YWRtaW46YWRtaW4=" \
-H "Accept:application/json" \
-H "Content-Type:application/json" \
-d \
'{
"Attributes": {
"Description": {
"value": "Newer value from the internet",
"act": "set"
}
}
}' \
'https://www14.v1host.com/v1sdktesting/rest-1.v1/Data/Issue/79242?sel=Name%2CDescription'
Accept:
标题的值进行格式化,因此如果您真的想要改变它,您实际上可以取回XML!?sel=Name,Description
属性,而不仅仅是"act": "set"
。如果您未能执行此操作,您仍会收到"value": "some new value..."
结果,但您不会看到修改后的值。答案 1 :(得分:1)
值得注意的是,当发布HTTP POST时,将Content-Type Header设置为application / json,到rest-1.v1/
端点并尝试更新多值关系,使用以下格式:<登记/>
<versionone-url>/rest-1.v1/Story
{
"Attributes": {
"ChangeSets": {
"name": "ChangeSets",
"value": [
{ "idref": "ChangeSet:1234", "act": "add" },
{ "idref": "ChangeSet:3456", "act": "add" }
]
}
}
}