Skip to content

Release 2.1.3+2589.4

Compare
Choose a tag to compare
@github-actions github-actions released this 25 Nov 23:09
ecc4125

This release fixes issue #152. It also contains an improvement (which happens to be a breaking change).

Fixes

  • Error when calling Invoke-TfsRestApi for different hosts in the same session: If you tried to call Invoke-TfsRestApi for a certain host (e.g. vsrm.dev.azure.com) and then call another host (e.g. vssps.dev.azure.com) it would fail. Internally, this cmdlet uses a custom VssHttpClientBase implementation called GenericHttpClient. This custom implementation has, among other things, the ability to call APIs hosted in different parts of Azure DevOps such as vsrm.dev.azure.com and vssps.dev.azure.com. However, once an instance of GenericHttpClient is created by a call to VssConnection.GetClient<T>(), it is cached internally by VssConnection and thus cannot be updated to point to another URL. This release fixes it.

Improvements

Invoke-TfsRestApi now unwraps the property "value" in the response (BREAKING)

In previous versions, Invoke-TfsRestApi would return the JSON response as-is.

In most situations, that would mean that using the code below would result in the following result:

PS> Invoke-TfsRestApi 'GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.1-preview.4'

count value
----- -----
    1 {@{source=userInterface; revision=27; description=; createdBy=; createdOn=2020-10-02T13:20:20.847Z; ...

Notice that the returned JSON response contains two properties, count and value. The value property contains the actual data. To access it, you most likely would have to use the following code:

PS> (Invoke-TfsRestApi 'GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.1-preview.4').value

source            : userInterface
revision          : 27
description       : This is a sample definition
createdBy         : @{displayName=Igor Abade...

That is a very common pattern used by the Azure DevOps APIs. So common, in fact, that it was almost guaranteed that the response would be wrapped in a property called "value" - which means that you're required to unwrap the value property nearly every time you called an Azure DevOps API.

Now, Invoke-TfsRestApi automatically expands the "value" property, so that now calls to Invoke-TfsRestApi will most certainly return the data you were looking for in the first place. However, that means your scripts may break, and you're required to manually fix them if you were using the (Invoke-TfsRestApi '_apis/...').value pattern.

To fix your scripts, you can either:

  • Add the -NoAutoUnwrap parameter to the call to Invoke-TfsRestApi; or
  • Remove the call to the Value property, replacing a code like (Invoke-TfsRestApi '_apis/...').value with Invoke-TfsRestApi '_apis/...'.