如何在给定的TFS Web扩展中获取文档集合列表? [英] How do I get a list of document collections in a given TFS web extension?
问题描述
我正在尝试使用Microsoft/vsts-node-api从本地TFS 2017(U3)Web扩展中获取文档列表.我可以通过以下类似的方式获取扩展程序本身
I'm trying to get a list of documents from my on premises TFS 2017 (U3) web extension using Microsoft/vsts-node-api. I can get the extension itself with something like the following
import * as v from 'vso-node-api';
import * as xa from 'vso-node-api/ExtensionManagementApi';
import * as xi from 'vso-node-api/interfaces/ExtensionManagementInterfaces';
let serverUrl = process.argv[2];
let extensionId = process.argv[3];
async function getWebApi(serverUrl): Promise<vm.WebApi> {
return new Promise<vm.WebApi>(async (resolve, reject) => {
try {
let token = getEnv('API_TOKEN'); // personal access token
let authHandler = v.getPersonalAccessTokenHandler(token);
let option = undefined;
let webApi: v.WebApi = new v.WebApi(serverUrl, authHandler, option);
let connData: lim.ConnectionData = await vsts.connect();
console.log('Hello ' + connData.authenticatedUser.providerDisplayName);
resolve(webApi);
}
catch (err) {
reject(err);
}
});
}
let vsts: v.WebApi = await getWebApi(serverUrl);
let vstsX: xa.IExtensionManagementApi = await vsts.getExtensionManagementApi();
let extension: xi.InstalledExtension =
(await vstsX.getInstalledExtensions()).find(x => x.extensionId === extensionId);
现在我想获取该扩展名中所有文档的列表.为此,我认为首先我必须获取该扩展名中的所有文档集合"(不要与TFS/VSTS集合混淆).我想我想要的API方法是queryCollectionsByName,它返回我想得到的ExtensionDataCollection数组,但是我不知道如何创建它想要的ExtensionDataCollectionQuery对象(它本身只是ExtensionDataCollection的数组).第一个参数.我不明白为什么它要使用ExtensionDataCollection数组作为输入参数-我想要扩展中的所有ExtensionDataCollections.
And now I want to get a list of all documents in that extension. To do that, I think first I have to get all the 'collections' of documents (not to be confused with TFS/VSTS collections) in that extension. I think the API method I want is queryCollectionsByName, which returns an array of ExtensionDataCollection which I think is what I want, but I don't know how to create the ExtensionDataCollectionQuery object (which is itself just an array of ExtensionDataCollection) it wants for the first parameter. I don't understand why it wants an array of ExtensionDataCollection as an input parameter - I want all of the ExtensionDataCollections in the extension.
我尝试过:
let collectionQuery: xi.ExtensionDataCollectionQuery;
let dataCollection : xi.ExtensionDataCollection[] =
await vstsX.queryCollectionsByName(collectionQuery, extension.publisherName, extension.extensionName);
但是我明白了
错误:值不能为空
Error: value cannot be null
The docs don't seem very helpful to me but maybe I'm not reading them properly: https://www.visualstudio.com/en-us/docs/integrate/extensions/reference/client/api/vss/references/sdk_interfaces/extensiondatacollectionquery
如何从Web扩展中获取文档集合列表?
How can I get a list of document collections from a web extension?
更新:REST URL
以另一种方式提出问题.
To put the question another way.
我可以使用以下URL获得已安装扩展的列表:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions
I can get a list of Installed Extension with this URL:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions
,如果我知道集合名称",则可以从一个集合中获取文档列表:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extensionName}/Data/Scopes/Default/Current/Collections/{collectionName}/Documents/
and I can get a list of documents from a collection if I know the "Collection Name":
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extensionName}/Data/Scopes/Default/Current/Collections/{collectionName}/Documents/
我可以使用哪个URL来获取给定扩展名中的收藏集列表?我尝试了这一点,这与我们获取扩展列表的方式类似,但我得到了404:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extensionName}/Data/Scopes/Default/Current/Collections
What URL can I use to get a list of Collections in a given extension? I tried this, which would be analagous to the way we get a list of extensions, but I get a 404:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extensionName}/Data/Scopes/Default/Current/Collections
推荐答案
这显然无法完成-您需要知道集合名称(以及扩展ID和发布者ID).
This apparently cannot be done - you need to know the Collection Names (as well as the extension ID and publisher ID).
然后,可以像这样检索集合中的文档:
Then, the documents in the collection can be retrieved like this:
let documentCollection =
await vstsX.getDocumentsByName(extension.publisherId, extension.extensionId, "Default", "Current", collectionName);
在这里参考: https://github.com/Microsoft/vsts-node-api/issues/160
这篇关于如何在给定的TFS Web扩展中获取文档集合列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!