Mukul
Mukul

Reputation: 371

Create work items in vsts with rest api using powershell?

I am trying to create a work-item in VSTS using power shell that I will be using with some of my custom solutions

Can anyone help me with the script?

Upvotes: 0

Views: 3299

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

Refer to this script:

param(
[string]$witType,
[string]$witTitle
)
$u="https://[account].visualstudio.com/DefaultCollection/[team project]/_apis/wit/workitems/`$$($witType)?api-version=1.0"
$body="[
  {
    `"op`": `"add`",
    `"path`": `"/fields/System.Title`",
    `"value`": `"$($witTitle)`"
  }
]"
$user = "test"
$token = "[personal access token]"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$result=Invoke-RestMethod -Method PATCH -Uri $u -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json-patch+json" -Body $body

Arguments: -witType "task" -witTitle "PowerShellWIT1"

Upvotes: 3

Related Questions