0

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://learn.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
}
4
  • 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. Commented Dec 25, 2020 at 8:20
  • @WalterQian-MSFT I tried the command without speicfying the version, but it still throw back the same error. Commented Dec 29, 2020 at 11:42
  • Please try to use installedextensionsbyname instead of installedextensions in your command. Please also check the screenshot of result in my answer. Commented Dec 30, 2020 at 7:38
  • 1
    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. Commented Dec 30, 2020 at 9:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

10 Comments

OK, I see. I don't know much about web app development, but if the api installedextensionsbyname is only useful in installing an extension which was previously installed on the server, then that beats my purpose. Is there a way to install the extension for the first time using the API. Anyway thank you so much for looking into it.
Please use the GET API in my answer first when you install extensions. Then, you can find them in local extensions. You just need to get the installContext at the first time. You can only use the api installedextensionsbyname to install the extensions that exist in local extensions.
I tried your get command. The returned error says, the command "install" and "installContext" is not written correctly or can't be found.
The output in the html format shows "A public action method 'items' was not found on controller 'Microsoft.VisualStudio.Services.Gallery.Web.GalleryController'."
Would you share your get command with me for further troubleshooting if you still have this issue?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.