'Azure DevOps PS REST API : No api-version was supplied for the \"PUT\" request. The version must be supplied either as part of the Accept header

I am trying to run below script to create and add data in Azure DevOps wiki page:

$JSONBody= @{
   "Content"="PR# $PullRequestId : $PullRequestTitle `n `n WorkItem# $workItemId : $taskTitle `n `n Iteration: $taskIterationPath `n `n Tags: $taskTags `n `n Description: `n `n $taskDescription" 
}

$wikiuri="https://dev.azure.com/{org_name}/{proj_name}/_apis/wiki/wikis/{wiki-proj-name}.wiki/pages?path=Release Notes/$todayDate/PR-$PullRequestId-$PullRequestTitle-$(RELEASE.ATTEMPTNUMBER)&api-version=5.0"

$Response=Invoke-RestMethod -Uri $wikiuri `
                            -Method PUT `
                            -Body ($JSONBody|ConvertTo-Json) `
                            -ContentType "application/json" `
                            -Headers @{Authorization=("Basic {0}" -f $Base64AuthInfo)}

Above script used to work just fine. But from last week or so, it started throwing below error:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":No api-version was supplied for the "PUT" request. The version must be supplied either as part of the Accept header (e.g. "application/json; api-version=1.0") or as a query parameter (e.g. "?api-version=1.0"). "typeName":"Microsoft.VisualStudio.Services.WebApi.VssVersionNotSpecifiedException, Microsoft.VisualStudio.Services.WebApi","typeKey":"VssVersionNotSpecifiedException","errorCode":0

Could you please help me to resolve this issue?

Thanks in advance



Solution 1:[1]

The error happens on your $wikiuri string. Use + to combine &api-version=5.0. Sample as below:

$wikiuri="https://dev.azure.com/{org_name}/{proj_name}/_apis/wiki/wikis/{wiki-proj-name}.wiki/pages?path=Release Notes/$todayDate/PR-$PullRequestId-$PullRequestTitle-$(RELEASE.ATTEMPTNUMBER)" + "&api-version=5.0"

Suggest to Write-Host $wikiuri to output the value for a check, make sure it has correct value with &api-version=5.0 ending and no special characters inside, since you are using variable here, eg: PullRequestTitle.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1