First, I gotta tell yah, I do not get the formatting in these windows. I surround my powershell code with <> inline code and its just bad... having said that:
I finally resolved this. You kind of missed a couple things.
First off, one needs to get the eTag using "Invoke-WebRequest"
`$uri = "https://dev.azure.com/${org}/${project}/_apis/wiki/wikis/${wikiName}/pages?path=/${pagePath}&includeContent=true&includeContentMetadata=true&api-version=7.1-preview.1"`
```` $response = Invoke-WebRequest -Uri $uri -Headers $Headers -Method Get`
` $eTag= $response.Headers["ETag"].Trim('"')`
And needed to use the "If-Match" = $eTag in the $Headers:
```yaml
`$uri = "https://dev.azure.com/${org}/${project}/_apis/wiki/wikis/${wikiName}/pages?path=${pagePath}&api-version=7.1-preview.1"`
```` `
`# $Headers is global, need to add "If-Match" = $eTag when updating a wiki page`
`# $Headers = @{`
`# 'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$accessToken"))`
`# }`
`# if ($eTag) {`
`# $localHeaders["If-Match"] = $eTag`
` # Create local copy of headers and add If-Match if needed`
` $localHeaders = @{}`
` foreach ($key in $Headers.Keys) {`
` $localHeaders[$key] = $Headers[$key]`
` }`
` # Build request body`
` if ($eTag) {`
` $localHeaders["If-Match"] = $eTag`
` $requestBody = @{`
` content = $content`
` version = @{ id = $eTag }`
` } | ConvertTo-Json -Depth 5`
` } else {`
` $requestBody = @{ content = $content } | ConvertTo-Json -Depth 5`
` }`
` # Define parameters`
` $params = @{`
` Uri = $uri`
` Headers = $localHeaders`
` Method = 'PUT'`
` ContentType = 'application/json; charset=utf-8'`
` Body = $requestBody`
` }`
` # Try to update the page`
` $result = Invoke-RestMethod @params`