Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create Azure Devops Wiki SubPage with PowerShell

I need to create a sub page in Azure Devops Wiki.

Here is the following code which create the main page and if i change the name the new page is created but not a following sub page.
There is no clear information to order or create sub page in official docs
https://docs.microsoft.com/fr-fr/rest/api/azure/devops/wiki/pages?view=azure-devops-rest-6.0
How can i achieve this?

$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"

$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath&api-version=6.0"

$Header = @{
    'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}

$params = @{
    Uri = $uri;
    Headers    = $Header;
    Method     = 'Put';
    ContentType = "application/json";
    body = $data;
}

Invoke-RestMethod @params

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From your Powershell Sample and Rest API url, you need to add the main page path to the path in the url.

https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=MainPagePath/$WikiSubPagePath&api-version=6.0

For example:

$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"

$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath/$WikiSubPagePath&api-version=6.0"

$Header = @{
    'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}

$params = @{
    Uri = $uri;
    Headers    = $Header;
    Method     = 'Put';
    ContentType = "application/json";
    body = $data;
}

Invoke-RestMethod @params

Then you can create a subpage under the main page.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading