skip to Main Content

In Azure DevOps, I’m encountering an issue where I cannot create a Project Wiki page via the API. I’m attempting to create a Project Wiki page using the REST API, but I’m consistently receiving a 404 HTTP error. I’m executing this operation from a build pipeline using a bash task with the ‘curl’ command.

Here is an example similar to the script I’m using:

API_VERSION=7.1
project=$(System.TeamProject)
wikiRepo=${project}.wiki
personalAccessToken=$(System.AccessToken)

url="https://dev.azure.com/$organization/$project/_apis/wiki/wikis/$wikiRepo/pages?path=my_page&api-version=$API_VERSION"


updateContent='{"content":"Foo Bar"}'

response=$(curl -i -X PUT 
  -H "Authorization: Bearer $personalAccessToken" 
  -H "Content-Type: application/json" 
  --data "$updateContent" 
  --url "$url")

I can confirm that the variables are correctly populated, and the Wiki defined in $wikiRepo does exist.

However, I consistently receive an HTTP code 404 and the following error message:
{"$id":"1","innerException":null,"message":"TF401019: The Git repository with name or identifier e2b297b8-965a-4a29-8541-bfbc0e6314a0 does not exist or you do not have permissions for the operation you are attempting.","typeName":"Microsoft.TeamFoundation.Git.Server.GitRepositoryNotFoundException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitRepositoryNotFoundException","errorCode":0,"eventId":3000}

Git repo mentioned in the error does not exist in the project.

The build service user has contributor permissions, which should allow it to add and edit Wiki pages.

The Wiki page my_page from the example does not exist. I expect the page to be created.

2

Answers


  1. In some cases, Build Services can not access the wiki even if they are added as a Contributor. Try to use your PAT instead of System.AccessToken. Maybe this is a bug or not.., but this is a good case to be added here: https://developercommunity.visualstudio.com/AzureDevOps

    Login or Signup to reply.
  2. You can check with the following things to resolve the issue:

    1. Ensure you have provided the correct URL of the Wiki repository that contains the right organization name, project name and repository name.

    2. If you run the bash task in a classic build pipeline, ensure you have enabled the option "Allow scripts to access the OAuth token" on the job-level.

      enter image description here

    3. On the Security hub of the Wiki, ensure the two identities "{Project Name} Build Service ({Organization Name})" and "Project Collection Build Service ({Organization Name})" have the ‘Read‘ and ‘Contribute‘ permissions set to ‘Allow‘.

      enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search