Padmapriya Kp
Padmapriya Kp

Reputation: 55

How to create multiple folders using Azure DevOps Rest API

I am using Azure DevOps rest api , to create folder in Releases. Not sure, how can I create multiple folders, subfolders in same path?

code :

'

Param( 
[string]$organisation = "org", 
[string]$project = "testdatafactory", 
[string]$keepForever = "true", 
[string]$user = "id", 
[string]$token = "token",
[string]$path= "\\") 

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

$uri = "https://vsrm.dev.azure.com/$organisation/$project/_apis/release/folders/$path ?api-version=6.0-preview"


Write-Host "Uri :" $uri

$params = 
@"
{
    "createdBy": "id",
    "createdOn": "",
   "description": "test",
   "lastChangedBy": "",
   "lastChangedDate": "",
   "path": "test1"
    }
"@


$result = Invoke-RestMethod -Uri $uri -Method POST -Body $params -Headers $headers -ContentType "application/json" -Verbose -Debug

'

Upvotes: 1

Views: 952

Answers (1)

Leo Liu
Leo Liu

Reputation: 76760

how can I create multiple folders, subfolders in same path?

I am afraid there is no such out of box way to create multiple folders, subfolders in same path.

That because there is no such Batch REST API for the Folders - Create.

As workaround, we could run the REST API multiple times to create the multiple folders, subfolders.

We could use the REST API:

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/folders?api-version=6.0-preview.2

Then specify the full path in the request body:

{
    "path": "\\Master\\test5",
    "createdBy": "id"
}

The test result:

enter image description here

enter image description here

And if we want to create the subfolders in the same path, we could just specify the path like: "path": "\\Master\\test5\\subfolder1":

enter image description here

Upvotes: 1

Related Questions