Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Error creating Work Items via Az Devops API and Powershell

Posted on by 6
Hi, I'm trying to develop a PowerShell script to create a workitem in azure devops following this post https://community.dynamics.com/blogs/post/?postid=61631256-4360-4b07-b343-43a855173cec
 
but i'm getting this error:
 
Invoke-RestMethod : 
  
    The controller for path '/orgname/projectname/apis/wit/workitems/$task' was not found or does not implement IController.
    html {
.
.
.
.
.
+ Invoke-RestMethod -Uri $uri -Method POST -Headers $AzureDevOpsAutheni ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
My script:
$AzureDevOpsPAT = 'blablabla' 

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic '+ 
[Convert]::ToBase64String([Text.Encoding]:: ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
 
$OrganizationName = "orgname" 

$UriOrganization= "https://dev.azure.com/$($OrganizationName)/" 
 
$WorkItemType = "task" #set there the WorkItemType

$WorkItemTitle = "Test from Powershell" #set the Title 

$ProjectName = "projectname"; # set the ProjectName

$uri = $UriOrganization + $ProjectName + "/apis/wit/workitems/$" + $WorkItemType + "?api-version=5.1" 
 
echo $uri 
 
$body="[
    {
        `"op`": `"add`",
        `"path`": `"/fields/System.Title`",
        `"value`":`"$($WorkItemTitle)`"
    }
]"
 
Invoke-RestMethod -Uri $uri -Method POST -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json-patch+json" -Body $body
 
Please, I don't know what's wrong :(
 
My Personal Access Token have full access and my user is a Project Collection Administrator.
Categories:
  • Verified answer
    UH-09100850-0 Profile Picture
    UH-09100850-0 12 on at
    Error creating Work Items via Az Devops API and Powershell
    I've got the same problem and could solve it by adding "accent de grave = ` " into my URL-Call.

    Try complete URL like this:
    "https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/`$Task?api-version=7.1"

    In Microsoft documentation:
    Work Items - Create - REST API (Azure DevOps Work Item Tracking) | Microsoft Learn
    POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=7.1

    Seems it need to be corrected/changed to:
    POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/`${type}?api-version=7.1

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans