0

We're automating our TFS Team/Board creation and found that there is an API to create a Team and an API to create an Area Path, but not one to link the two. Basically we're looking for something that acts as the ‘Create an area path with the name of the team.’ check box in the attached picture.Screenshot Here's the code for our Team post:

$azdoURI = https://prd-ourCompanyName/tfs/ourOrg/_apis/projects/ourProject/teams?api-version=5.0"
$requestBody = @{ name = "$boardName" }
$jsonRequestBody = $requestBody | ConvertTo-Json -Compress

$response = (Invoke-WebRequest -Method Post -Uri $azdoURI -Body $jsonRequestBody -Content 'application/json' -Credential $credential -UseBasicParsing)
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
pharmer40
  • 11
  • 2
  • Does the team means team project? Which rest api do you use? – Pod Mo Apr 09 '20 at 10:20
  • Yes - Team as in a Team within the team project. We have a successful function that I just added to the post above that adds the Team. From the Microsoft docs, the POST below should add the Area Path. I just haven't found a way to tie them both together. POST https://dev.azure.com/{organization}/{project}/_apis/wit/classificationnodes/{structureGroup}/{path}?api-version=5.1 – pharmer40 Apr 10 '20 at 13:00
  • The old API examles can be found here: https://stackoverflow.com/a/12850331/736079 – jessehouwing Apr 10 '20 at 13:20
  • Hi pharmer40, is there any update for this issue? – LoLance Apr 23 '20 at 05:53

3 Answers3

0

Adding an iteration to a team is done through the /_apis/work/teamsettings/iterations API.

Request:

POST https://dev.azure.com/fabrikam/Fabrikam-Fiber/_apis/work/teamsettings/iterations?api-version=5.1
"{\"id\":\"a589a806-bf11-4d4f-a031-c19813331553\"}"

Response:

{
  "id": "a589a806-bf11-4d4f-a031-c19813331553",
  "name": "Sprint 2",
  "path": "Fabrikam-Fiber\\Release 1\\Sprint 2",
  "attributes": {
    "startDate": null,
    "finishDate": null
  }
}

To set area paths use the /_apis/work/teamsettings/teamfieldvalues:

Request:

PATCH https://dev.azure.com/fabrikam/Fabrikam-Fiber/_apis/work/teamsettings/teamfieldvalues?api-version=5.1
{
  "defaultValue": "Fabrikam-Fiber\\Auto",
  "values": [
    {
      "value": "Fabrikam-Fiber\\Auto",
      "includeChildren": true
    },
    {
      "value": "Fabrikam-Fiber\\Fiber",
      "includeChildren": false
    },
    {
      "value": "Fabrikam-Fiber\\Optics",
      "includeChildren": false
    }
  ]
}

Response:

{
  "field": {
    "referenceName": "System.AreaPath",
    "url": "https://dev.azure.com/fabrikam/_apis/wit/fields/System.AreaPath"
  },
  "defaultValue": "Fabrikam-Fiber\\Auto",
  "values": [
    {
      "value": "Fabrikam-Fiber\\Auto",
      "includeChildren": true
    },
    {
      "value": "Fabrikam-Fiber\\Fiber",
      "includeChildren": false
    },
    {
      "value": "Fabrikam-Fiber\\Optics",
      "includeChildren": false
    }
  ]
}

See also:

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • To your knowledge, is there a way to do this with the Client SDK? [Here's the problem](https://stackoverflow.com/q/65472137) I'm trying to solve. – InteXX Dec 28 '20 at 03:17
0

Basically we're looking for something that acts as the ‘Create an area path with the name of the team.’ check box in the attached picture.

If I understand you well, you're trying to create a new Team Project in which there's one default Area path. (Of course you also want their names should be the same)

For TFS2018U2, try:

POST https://{instance}/{collection}/_apis/projects?api-version=4.1

For Azure Devops Server 2019, try:

POST https://{instance}/{collection}/_apis/projects?api-version=5.0

You can find more details from my another post here. After my check, this api will automatically define the default area path with same name like Team project's:

enter image description here

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Sorry for the delay - Our story dropped out for a while. This looks like what I needed. Am going to try soon. – pharmer40 Aug 12 '20 at 14:08
  • To your knowledge, is there a way to do this with the Client SDK? [Here's the problem](https://stackoverflow.com/q/65472137) I'm trying to solve. – InteXX Dec 28 '20 at 03:18
0

So here's where I ended up: 5 Steps:

  1. Create team: POST https://dev-tfs.../{organization}/_apis/projects/{project}/teams?api-version=5.1 Body: {"name":"BoardByPostmanTest_3"}
  2. Create Area Path to match team: POST https://dev-tfs.../{organization}/{project}/_apis/wit/classificationnodes/Areas?api-version=5.1 Body: {"name":"BoardByPostmanTest_3"}
  3. Update Team with Area path: PATCH https://dev-tfs.z../{organization}/{project}/BoardByPostmanTest_3/_apis/work/teamsettings/teamfieldvalues?api-version=5.1 Body: { "defaultValue": "Agile\BoardByPostmanTest_3", "values": [ { "value": "Agile\BoardByPostmanTest_3", "includeChildren": true } ] }
  4. Find Iteration for project: GET https://dev-tfs.../{organization}/{project}/_apis/wit/classificationnodes/Iterations?api-version=5.1
  5. Add that Iteration to Team: PATCH https://dev-tfs.../{organization}/{project}/BoardByPostmanTest_3/_apis/work/teamsettings?api-version=5.1 Body: { "backlogIteration": "whatever that Iteration number is from GET in step 4" }

Thank you to jessehouwing for step 3 that I was missing.

pharmer40
  • 11
  • 2