【发布时间】:2021-03-19 10:08:39
【问题描述】:
当我尝试使用 Rest API 在 Azure Devops 中创建工作项时出现以下错误。
这是我正在使用的 PowerShell 脚本
$body ='[{"op": "add", "path": "/fields/System.Title", "from": null, "value": "Initiative Code"}]' | ConvertTo-Json
$body = $body | ConvertFrom-Json
$supportAreaUri = 'https://MyOrganization.visualstudio.com/TestTeam1/_apis/wit/workitems/$Initiative?api-version=6.0'
$supportAreaUri = [uri]::EscapeUriString($supportAreaUri)
$supportArea = Invoke-RestMethod -Method Post -Uri $supportAreaUri -Headers $Header -ContentType application/json -Body $body
运行代码时出现此错误:
"$id": "1",
“内部异常”:空,
"message": "请求为方法类型 "POST" 指明 Content-Type 为 "application/json",但不受支持。此方法的有效内容类型为:application/json-patch+json。",
"typeName": "Microsoft.VisualStudio.Services.WebApi.VssRequestContentTypeNotSupportedException, Microsoft.VisualStudio.Services.WebApi",
"typeKey": "VssRequestContentTypeNotSupportedException",
“错误代码”:0,
“eventId”:3000
当我在 Postman 中尝试 Post 请求时,我遇到了同样的错误。
【问题讨论】:
-
您是否仔细查看了错误消息和文档并尝试相应地调整您的代码? 此方法的有效内容类型为:application/json-patch+json。
标签: azure powershell rest azure-devops