How to fix the error "The remote server returned an error: (405) Method Not Allowed" while trying to automate wiki documentation from azure release pipeline. This occurs when trying to update/create the wiki page from azure build pipeline using PS script.

Tiwari, M (Manika) 0 Reputation points
2023-06-07T07:35:17.0633333+00:00

Error details:

Starting: Wiki creation

  1. ==============================================================================

Task : PowerShell

Description : Run a PowerShell script on Linux, macOS, or Windows

Version : 2.220.0

Author : Microsoft Corporation

Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell

==============================================================================

Generating script.

Formatted command: . 'D:\a\1\s\CreateReleaseWiki\ReleaseWikiNew.ps1' -ADOPatToken *** -wikiName LSSV.DLL.VFW.LSS.WebAPI.PRD-wiki -wikiRepoName Infra-Release-Management-Wiki -releasePipelineName LSSV.DLL.VFW.LSS.WebAPI.PRD

========================== Starting Command Output ===========================

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a_temp\74741243-945f-46d8-a570-d1d99bdf87e0.ps1'"

Wiki name is LSSV.DLL.VFW.LSS.WebAPI.PRD-wiki

Connection is working name is @{source=restApi; revision=20; description=; createdBy=; createdOn=2023-02-09T15:19:29.08Z; modifiedBy=; modifiedOn=2023-04-24T16:47:54.2Z; isDeleted=False; variableGroups=; releaseNameFormat=$(Release.DefinitionName)-$(rev:r); properties=; id=1331; name=LSSV.DLL.VFW.LSS.WebAPI.PRD; path=\WINDOWS\LSSV; projectReference=; url=https://vsrm.dev.azure.com/dllgroup/a4327030-0408-418d-b38c-c49edfc4ab5d/_apis/Release/definitions/1331; _links=} @{id=5cd0510e-b4db-4936-aa6f-f36dccb7eeb0; versions=System.Object[]; url=https://dev.azure.com/dllgroup/a4327030-0408-418d-b38c-c49edfc4ab5d/_apis/wiki/wikis/5cd0510e-b4db-4936-aa6f-f36dccb7eeb0; remoteUrl=https://dev.azure.com/dllgroup/a4327030-0408-418d-b38c-c49edfc4ab5d/_wiki/wikis/5cd0510e-b4db-4936-aa6f-f36dccb7eeb0; type=codeWiki; name=Infra Release Management; projectId=a4327030-0408-418d-b38c-c49edfc4ab5d; repositoryId=06d4f6af-8b9e-4129-95fd-4d244cfc8765; mappedPath=/} is working

Page exists

MD file is created LSSV.md

Failed to create the Wiki page. Error: The remote server returned an error: (405) Method Not Allowed.

New page is created False

Failed to update the Wiki page. Error: The remote server returned an error: (405) Method Not Allowed.

False

Finishing: Wiki creation

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,861 Reputation points
    2023-06-08T10:19:54.5866667+00:00

    Hello Tiwari,

    Thank you for your question and for reaching out with your question today.

    The error "The remote server returned an error: (405) Method Not Allowed" indicates that the HTTP request made by your PowerShell script is using a method that is not allowed by the server.

    To resolve this issue, you can try the following steps:

    1. Check the HTTP method: Review your PowerShell script and verify the HTTP method you are using for the request. Ensure that it is appropriate for creating or updating a wiki page. The most common methods for creating or updating resources are POST or PUT.
    2. Confirm the endpoint URL: Double-check the endpoint URL you are using to access the Azure DevOps Wiki API. Make sure it is correct and matches the expected format. The URL should include the organization, project, and wiki information.
    3. Validate authentication: Ensure that your script is properly authenticated and authorized to access the Azure DevOps Wiki. You may need to include authentication headers or tokens in your request to authenticate with the Azure DevOps API.
    4. Verify permissions: Verify that the user or service account executing the PowerShell script has the necessary permissions to create or update wiki pages. The account should have appropriate access rights within the Azure DevOps organization and project.
    5. Test the request with a REST client: To troubleshoot further, you can use a REST client (such as Postman or cURL) to manually send a request to the Azure DevOps Wiki API and observe the response. This can help you verify if the issue is specific to your PowerShell script or if it is a configuration issue on the server side.
    6. Review API documentation: Refer to the official documentation or API reference for the Azure DevOps Wiki API to ensure that you are following the correct syntax and guidelines for creating or updating wiki pages.
    7. Check for any restrictions or limitations: Some APIs may have restrictions or limitations on certain operations. Make sure you are not violating any specific constraints or limitations imposed by the Azure DevOps Wiki API.

    If the issue persists, you may need to reach out to the Azure DevOps support team or consult their official documentation for specific troubleshooting steps related to the Wiki API.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    Best regards.

    0 comments No comments

  2. Thomas Murnane 81 Reputation points
    2025-08-12T20:28:25.8+00:00

    I know this is old but thought I would help with actual powershell code. I kept trying to use Invoke-RestMethod, but found you need to get the eTag from the headers via an Invoke-WebRequest. I wanted to get the content, manipulate it and write it back if the page existed else create the page with the contents so I created a function to basically get the content and return the eTag; assuming your wiki is git based.

    function Get-WikiPageContent {
    param(
    [Parameter(Mandatory=$true)][string]$pagePath
    )
    $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
    # You need the eTag (Commit ID) to update a wiki page
    $eTag= $response.Headers["ETag"].Trim('"')

    # Convert only the JSON content of the response
    $pageData = $response.Content | ConvertFrom-Json
    $pageData | ConvertTo-Json -Depth 10 | Out-Host

    return [pscustomobject]@{
    PagePath = $pagePath
    eTag = $eTag
    Content = $pageData.content
    }
    }

    Now when writing the content back to the page, you need to add the "If-Match = "$eTag" to the Headers before calling Invoke-RestMethod, I have a global $Headers definition and I just copy it in function and add the eTag

    function Set-PageContent {
    param(
    [Parameter(Mandatory = $true)][string]$pagePath,
    [Parameter(Mandatory = $true)]$content,
    [string]$eTag # This is the eTag, only present if page exists
    )

    $uri = "https://dev.azure.com/${org}/${project}/_apis/wiki/wikis/${wikiName}/pages?path=${pagePath}&api-version=7.1-preview.1"

    # Create local copy of headers and add If-Match if needed
    $localHeaders = @{}
    foreach ($key in $Headers.Keys) {
    $localHeaders[$key] = $Headers[$key]
    }

    # If updating page, must give eTag
    if ($eTag) {
    $localHeaders["If-Match"] = $eTag
    }

    $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 Catch
    $result = Invoke-RestMethod @params
    }

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.