Answers: <p>Your script works, just update the last content type to <code>application/json</code>:</p>
  <pre><code>Invoke-RestMethod -Uri $adoTaskUri -ContentType &quot;application/json&quot; -Body $body -headers $adoHeader -Method POST
  </code></pre>
  <p>PATCH is used to update a team project: <a href="https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/update?view=azure-devops-rest-6.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/azure/devops/core/projects/update?view=azure-devops-rest-6.1</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-12T12:02:31.123Z
Answers: it's frustrating how long I search on something so logical. Thank you
Answers: Brtrnd
Answers: CC BY-SA 4.0
Answers: 2021-02-12T11:44:44.453Z
Answers: 2021-02-12T11:44:44.453Z
Answers: Shamrai Aleksander
Body: <p>I'm creating a a project with the code below.<br />
  The response is always an unspecified error.</p>
  <blockquote>
  <p>Invoke-RestMethod :
  {&quot;$id&quot;:&quot;1&quot;,&quot;innerException&quot;:null,&quot;message&quot;:&quot;TF400898: An Internal
  Error Occurred. Activity Id:
  3fbed4b2-9751-41ba-acbe-4d20f02ae556.&quot;,&quot;typeName&quot;:&quot;System.Web.Http.HttpResponseException,
  System.Web.Http&quot;,&quot;typeKey&quot;:&quot;HttpResponseException&quot;,&quot;errorCode&quot;:0,&quot;eventId&quot;:0}<br />
  At line:1 char:1<br />
  Invoke-RestMethod -Uri $adoTaskUri -ContentType &quot;application/json-pat ...<br />
  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~<br />
  CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException<br />
  FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand</p>
  </blockquote>
  <p>I tried the body in postman and the projects are created just fine.</p>
  <p>Can someone see what I'm doing wrong?<br />
  Listing of the projects works; the body works in postman; I can create tasks with a similar script.</p>
  <pre><code>$pacToken = &quot;&quot;
  $organizationName = &quot;BLECUST&quot;
  
  $adoHeader = @{&quot;Accept&quot;=&quot;application/json&quot;;Authorization=(&quot;Basic {0}&quot; -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((&quot;{0}:{1}&quot; -f &quot;&quot;,$pacToken))))}
  #$adoHeader #accept about anything and add security in the header
  
  #api to create 
  $adoTaskUri = &quot;https://dev.azure.com/BLECUST/_apis/projects?api-version=5.1&quot;
  
  
  #list all projects
  $response = Invoke-RestMethod -Uri $adoTaskUri -ContentType &quot;application/json-patch+json&quot;  -headers $adoHeader -Method GET
  $response.value | ft name, visibility, url
  
  $body='{
    &quot;name&quot;: &quot;FabrikamTravel18&quot;,
    &quot;description&quot;: &quot;Frabrikam travel app for Windows Phone&quot;,
    &quot;capabilities&quot;: {
      &quot;versioncontrol&quot;: {
        &quot;sourceControlType&quot;: &quot;Git&quot;
      },
      &quot;processTemplate&quot;: {
        &quot;templateTypeId&quot;: &quot;6b724908-ef14-45cf-84f8-768b5384da45&quot;
      }
    }
  }'
  
  
  Invoke-RestMethod -Uri $adoTaskUri -ContentType &quot;application/json-patch+json&quot; -Body $body-headers $adoHeader -Method POST
  </code></pre>
  
Tags: <azure-devops><powershell>
Title: REST API: create project with powershell returns unspecified internal error
UserDisplayName: Brtrnd
ThreadText: # REST API: create project with powershell returns unspecified internal error
  
  (Asked by: username_0 on 2021-02-11)
  
  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
  
  $body='{
    "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
  
  ```
  
  **Tags:** azure-devops, powershell
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-12. Score: 3 | Accepted answer
  
  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>
  
  > **Comments:**
  > **username_0**: it's frustrating how long I search on something so logical. Thank you  
  
  ---
  
  