2
votes

I'm trying to set the areas that are associated with a team on a TFS 2017 on-premise server using the rest API and powershell.

When I try to invoke my URI

http://MyTfsServer:8080/tfs/DefaultCollection/TeamProject/TeamName/_apis/Work/TeamSettings/TeamFieldValues?api-version=2.0-preview.1

as explained in the API example with a json package, I get the following error return:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.
\r\nParameter name: patch","typeName":"System.ArgumentNullException, mscorlib, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
+ ...   $result = Invoke-RestMethod -Method Patch -Uri $setTeamAreaPathUri  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I could really use som guidance as to what I should look for. I've verified my Json package and it should be well-formed.
{
   "defaultValue":  "TeamProject\\Area1",
    "Values":  [
                   {
                       "value":  "Area2\\Area21\\Area211",
                       "includeChildren":  false
                   },
                   {
                       "value":  "Area3\\Area31\\Area311",
                       "includeChildren":  false
                   }
               ]

}

Update

I'm invoking the above URI with the powershell Invoke-RestMethod cmdlet

Invoke-RestMethod -Method Patch -Uri $setTeamAreaPathUri -UseDefaultCredentials -Body $json -ContentType "application/json"

Where $setTeamAreaPathUri corresponds to the above http URI. Should I be using post as my webrequest method as opposed to patch?

I'm perfectly able to get a response from the same URI using a get request. However, unable to alter the existing team areas using the patch method :-(

Update 2

This seems related to the Scandinavian chars 'æøå' being included in the area path. If I exclude all the area paths which include either æ,ø or å, I get no error. That wasn't obvious from my example... sorry! Is there a way to parse in the json so the TFS server won't break on it? Or is this because of me lacking profiency in powershell rest api invoking?

2
Could you please post your invoke-webrequest code. ? YOur Json is valid but the parsing seems different.Ranadip Dutta
Can't reproduce your issue, did you give a try with some rest client such as postman to test your rest api and json body? Also give a try with \\Area2 instead of Area2\\Area21\\Area211PatrickLu-MSFT

2 Answers

3
votes

It appears this was all related to the area paths containing special chars e.g. æ,ø,å which are predominantly used in Scandinavia.

If I specified my content type when calling invoke-restmethod as

-ContentType "application/json;charset=utf-8"

I have no issue what so ever calling the patch method of the API.

Sorry for the inconvenience!

And thank you for your help!

0
votes

I cannot repro this issue either. This seems to be happening because of patch object being null. Could you try this with postman to test the api? Also, the default value should be one of the team's allowed team field values.