0
votes

I am trying to use the REST API of TFS 2018 to install an extension on our server with the help of cURL. This process must be repeated everyday, and that's why I'd like to run it using a command with cURL.

So far I figured out how to get a list of all the installed extensions on the server with the following command. This tells me the connection and the authentication work well.

curl -u {username}:{PAT} -d "" -X GET http://{instance}/{collection}/_apis/extensionmanagement/installedextensions?api-version=4.1-preview.1

To install the extension I have read this info from microsoft doc: https://docs.microsoft.com/en-us/rest/api/azure/devops/extensionmanagement/installed%20extensions/install%20extension%20by%20name?view=vsts-rest-tfs-4.1

I try formulate a command to install an extension I found here:https://marketplace.visualstudio.com/items?itemName=benjhuser.tfs-extensions-build-tasks.

The command is:

curl -u {username}:{PAT} -H "Content-Type: application/json" -X POST http://{instance}/{collection}/_apis/extensionmanagement/installedextensionsbyname/benjhuser/tfs-extensions-build-tasks/3.0.14?api-version=4.1-preview.1

I think the publisher, id and version of the extension should be correct, because I took them from this release document: https://github.com/huserben/TfsExtensions/blob/master/BuildTasks/vss-extension.json.

The response says the extension doesn't exist. This is confusing. Could someone please give me some hints, what the problem can be? Thank you in advance.

{
  "$id": "1",
  "innerException": null,
  "message": "The requested extension 'benjhuser.tfs-extensions-build-tasks' doesn't exist.",
  "typeName": "Microsoft.VisualStudio.Services.Gallery.WebApi.ExtensionDoesNotExistException, Microsoft.VisualStudio.Services.Gallery.WebApi",
  "typeKey": "ExtensionDoesNotExistException",
  "errorCode": 0,
  "eventId": 3000
}
1
Hi friend, does the answer below resolved your question? If my reply helped or gave a right direction. Appreciate for marking it as an answer which will also help others in the community. - Walter
@WalterQian-MSFT I tried the command without speicfying the version, but it still throw back the same error. - Vincent
Please try to use installedextensionsbyname instead of installedextensions in your command. Please also check the screenshot of result in my answer. - Walter
Hi friend, please use another GET API first before installing the extensions. I updated my answer. Feel free to contact me if you have any confusion. - Walter

1 Answers

1
votes

The Install Extension By Name Rest API is used to Install pre-installed extensions. You need to add the extensions locally. Please refer to the document about Install extensions for on-premises servers.

Please try the following steps:

1.Open the developer tool(F12) of the browser and click install button. You can find the publisher name and extension name in the URL.enter image description here 2.Check the network tab in the developer tool(F12). You can find a REST API like

GET http://{instance}/{collection}/_gallery/items?itemName={publisher name}.{extension name}&install=true&installContext={Some context}.

The installContext will not change, you only need to change the publisher name and extension name here every time you install a new extension: enter image description here 3.Now, you can find this extension in the local extensions. enter image description here

After this, you can use the Install Extension By Name API to Install Extensions.

Steps summery:

1.curl -u {username}:{PAT} -X GET http://{instance}/{collection}/_gallery/items?itemName=benjhuser.tfs-extensions-build-tasks&install=true&installContext={installContext}

2.curl -u {username}:{PAT} -d "" -H "Content-Type: application/json" -X POST http://{instance}/{collection}/_apis/extensionmanagement/installedextensionsbyname/benjhuser.tfs-extensions-build-tasks?api-version=4.1-preview.1

Here is my result: enter image description here

In addition, Azure DevOps Services can use Install Extension By Name API directly.