Azure DevOps Server Invoke-RestMethod Error No API version provided for the PUT request

0 votes

I tried to pass data to the Azure DevOps Server (2019.0.1) REST API based on this  PowerShell example.

I modified the example like this :

# DEMO 5 Update an environment build variable

Write-Host "Demo 5"

$projects.value | ForEach-Object {

    $project = $_.name

    $buildManagementAreaId = "efc2f575-36ef-48e9-b672-0c6fb4a48ac5"

    $tfsBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $buildManagementAreaId

    # https://docs.microsoft.com/en-us/rest/api/azure/devops/build/definitions/list?view=azure-devops-rest-5.0

    $relDefUrl = "$tfsBaseUrl$project/_apis/build/definitions?api-version=5.0"

    Write-Host "Requesting URL: $relDefUrl" -ForegroundColor Yellow

    $result = Invoke-RestMethod $relDefUrl -Method Get -ContentType "application/json" -Headers $header

    $relDefs = $result.value

    if($relDefs.count -gt 0){

        Write-Host "$project $($relDefs.count) build def founds" -ForegroundColor Blue

        $relDefs | ForEach-Object {

            $relDef = $_

            $relDefExpanded = Invoke-RestMethod "$($relDef.url)?`$Expand=Environments&api-version=5.0" -Method Get -ContentType "application/json" -Headers $header

            $relDefExpanded.project.description = "Hallo!!!"

            $body = $relDefExpanded | ConvertTo-Json -Depth 100 -Compress

            $body = [System.Text.Encoding]::UTF8.GetBytes($body)

            #ERROR OCCURS HERE

            $updateResult = Invoke-RestMethod "$($relDef.url)?api-version=5.0" -Method Put -ContentType "application/json" -body $body -Headers $header 

            Write-host "Variable value after: $($updateResult.project.description)" -ForegroundColor Green

        }

    }

}

An error occures in this line of code:

$updateResult = Invoke-RestMethod "$($relDef.url)?api-version=5.0" -Method Put -ContentType "application/json" -body $body -Headers $header 

Error message :

Invoke-RestMethod: {"$ id": "1", "innerException": null, "message": "No API version provided for the" PUT "request The version must either be part of the" Accept "header (eg

\ "application / json; api-version = 1.0 \") or as a query parameter (for example, "? api-version = 1.0")

. Will "," type name ":" Microsoft.VisualStudio.Services.WebApi.VssVersionNotSpecifiedException,

Microsoft.VisualStudio.Services.WebApi","typeKey":"VssVersionNotSpecifiedException","errorCode":0,"eventId":3000}

In C:\Users\mkober\Desktop\Azure DevOps Console\WriteAPI.ps1:75 Zeichen:29

+ ... ateResult = Invoke-RestMethod "$($relDef.url)?api-version=5.0" -Metho ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

How do I overcome this error? And why did the error occur?

Apr 14, 2022 in Other DevOps Questions by Kichu
• 19,040 points
1,339 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Other DevOps Questions

0 votes
1 answer

How to integrate OnPrem Azure DevOps Server with the cloud one?

When I go to Project > Boards ...READ MORE

answered Feb 11, 2022 in Other DevOps Questions by Bhavitha
• 1,000 points
635 views
0 votes
0 answers

How is the Azure DevOps Service version determined?

Azure DevOps Service has a version number ...READ MORE

Mar 22, 2022 in Other DevOps Questions by Kichu
• 19,040 points
338 views
0 votes
0 answers
0 votes
0 answers

How to get all repos in Azure DevOps?

I'm working on several Azure DevOps initiatives. ...READ MORE

Dec 13, 2022 in DevOps on Cloud by Edureka
• 13,620 points
1,020 views
0 votes
0 answers
0 votes
0 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP