I'm creating a a project with the code below.
The response is always an unspecified error.

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: 3fbed4b2-9751-41ba-acbe-4d20f02ae556.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException","errorCode":0,"eventId":0}
At line:1 char:1
Invoke-RestMethod -Uri $adoTaskUri -ContentType "application/json-pat ...
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I tried the body in postman and the projects are created just fine.

Can someone see what I'm doing wrong?
Listing of the projects works; the body works in postman; I can create tasks with a similar script.

$pacToken = ""
$organizationName = "BLECUST"

$adoHeader = @{"Accept"="application/json";Authorization=("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$pacToken))))}
#$adoHeader #accept about anything and add security in the header

#api to create 
$adoTaskUri = "https://dev.azure.com/BLECUST/_apis/projects?api-version=5.1"

#list all projects
$response = Invoke-RestMethod -Uri $adoTaskUri -ContentType "application/json-patch+json"  -headers $adoHeader -Method GET
$response.value | ft name, visibility, url

  "name": "FabrikamTravel18",
  "description": "Frabrikam travel app for Windows Phone",
  "capabilities": {
    "versioncontrol": {
      "sourceControlType": "Git"
    "processTemplate": {
      "templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45"

Invoke-RestMethod -Uri $adoTaskUri -ContentType "application/json-patch+json" -Body $body-headers $adoHeader -Method POST

1 Answer 1


Your script works, just update the last content type to application/json:

Invoke-RestMethod -Uri $adoTaskUri -ContentType "application/json" -Body $body -headers $adoHeader -Method POST

PATCH is used to update a team project: https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/update?view=azure-devops-rest-6.1

  • 1
    it's frustrating how long I search on something so logical. Thank you
    – Brtrnd
    Feb 12, 2021 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.