通过其余api更新服务连接

时间:2019-09-25 17:33:03

标签: azure-devops azure-devops-rest-api

我正在尝试为服务连接建立密钥轮换。但是,当遵循Rest API文档时,我不断收到以下错误。

https://docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpoints/update%20service%20endpoint?view=azure-devops-rest-5.1

$projectApi = "https://dev.azure.com/collection/teamproject/_apis/serviceendpoint/endpoints/ffffffff-ffff-ffff-ffff-ffffffffffff?api-version=5.0-preview.2"
$json = "{
    ""data"": {
        ""subscriptionId"": ""ffffffff-ffff-ffff-ffff-ffffffffffff"",
        ""subscriptionName"": ""subscriptionName"",
        ""environment"": ""AzureCloud"",
        ""scopeLevel"": ""Subscription"",
        ""creationMode"": ""Manual""
    },  
    ""id"": ""ffffffff-ffff-ffff-ffff-ffffffffffff"",
    ""name"": ""Azure Service Connection"",
    ""type"": ""azurerm"",
    ""url"": ""https://management.azure.com/"",
        ""createdBy"": {
        ""id"": ""ffffffff-ffff-ffff-ffff-ffffffffffff"",
        ""displayName"": ""me"",
        ""uniqueName"": ""me@domain.onmicrosoft.com"",
        ""url"": ""https://spsprodcus3.vssps.visualstudio.com/ffffffff-ffff-ffff-ffff-ffffffffffffe/_apis/Identities/ffffffff-ffff-ffff-ffff-ffffffffffff"",
        ""imageUrl"": ""https://dev.azure.com/teamproject/_apis/GraphProfile/MemberAvatars/aad.ffffffffffffffffffffffffffffffffffffffffffffffff""
    },
    ""authorization"": {
        ""parameters"": {
            ""tenantid"": ""ffffffff-ffff-ffff-ffff-ffffffffffff"",
            ""serviceprincipalid"": ""test"",
            ""authenticationType"": ""spnKey"",
            ""serviceprincipalkey"": ""test""
        },
        ""scheme"": ""ServicePrincipal""
    }
    ""isReady"": true
}
"
$result = Invoke-RestMethod -Uri $projectApi -Method Put -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $DevOpsAuthentication)} -Body $json

这是我在拨打电话时收到的错误。

  

Invoke-RestMethod:{“ $ id”:“ 1”,“ innerException”:null,“ message”:“ Value   不能为null。\ r \ n参数名称:   端点“,” typeName“:” System.ArgumentNullException,   mscorlib“,” typeKey“:” ArgumentNullException“,” errorCode“:0,” eventId“:0}   在C:\ temp \ Scripts \ ServiceConnectionsTemp.ps1:49 char:11   + $ result =调用-RestMethod -Uri $ projectApi -Method Put -ContentType ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + + CategoryInfo:InvalidOperation:   (System.Net.HttpWebRequest:HttpWebRequest)[Invoke-RestMethod],   WebException + FullyQualifiedErrorId:   WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

什么参数为空?该文档未列出任何提及端点或类型名称的内容。

1 个答案:

答案 0 :(得分:2)

授权后缺少逗号。

谢谢