我正在尝试使用Microsoft / vsts-node-api从我的内部TFS 2017(U3)Web扩展中获取文档列表。我可以使用类似下面的内容获取扩展名
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。
我试过了:
let collectionQuery: xi.ExtensionDataCollectionQuery;
let dataCollection : xi.ExtensionDataCollection[] =
await vstsX.queryCollectionsByName(collectionQuery, extension.publisherName, extension.extensionName);
但是我得到了
错误:值不能为空
文档似乎对我没有帮助,但也许我没有正确阅读它们:https://www.visualstudio.com/en-us/docs/integrate/extensions/reference/client/api/vss/references/sdk_interfaces/extensiondatacollectionquery
如何从网络扩展程序中获取文档集合列表?
更新:REST网址
以另一种方式提出问题。
我可以使用以下网址获取已安装的扩展程序列表:
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/
我可以使用哪个URL来获取给定扩展名中的集合列表?我试过这个,这与我们获得扩展列表的方式类似,但我得到了404:
https://{account}.extmgmt.visualstudio.com/_apis/ExtensionManagement/InstalledExtensions/{publisherName}/{extensionName}/Data/Scopes/Default/Current/Collections
答案 0 :(得分:0)
这显然无法完成 - 您需要知道收集名称(以及扩展ID和发布商ID)。
然后,可以像这样检索集合中的文档:
empty_vec <- rep("", times=length(number_vec))
答案 1 :(得分:0)
目前,我面临着同样的问题。愿有人帮助。我编写了一个Powershell脚本,涉及以下场景:
创建文档
获取所有文档
修补文档
删除所有文档
范围类型:集合
作为VSS SDK的参考,请查看Data storage
#VARIABLES TO SET
$Uri = "{devops url}"
$Collection = "{collection name}"
$PAT = "{personal access token}"
$Publisher = "{publisher of extension}"
$Extension = "{name of extension}"
#JSON FILE TO UPLOAD
$jsonFile = "{ 'A': { 'A1': 10, 'A2': 20 }, 'B': { 'B1': 30, 'B2': 40 } }"
#AUTHORIZATION HEADERS
$headers = @{
"Authorization" = ('Basic {0}' -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)")))
"If-Match" = ""
}
#CREATE DOCUMENT
$body = $jsonFile
$api = "api-version=3.1-preview.1"
$url = "$Uri/$Collection/_apis/ExtensionManagement/InstalledExtensions/$Publisher/$Extension/Data/Scopes/Default/Current/Collections/$Collection/Documents?$api"
$result = Invoke-RestMethod -Uri $url -Method POST -ContentType "application/json" -Headers $headers -Body $body -TimeoutSec $timeout -Verbose
Write-Host "[ps1] create document: $result" -ForegroundColor Green
#GET ALL DOCUMENTS
$url = "$Uri/$Collection/_apis/ExtensionManagement/InstalledExtensions/$Publisher/$Extension/Data/Scopes/Default/Current/Collections/$Collection/Documents?"
$result = Invoke-RestMethod -Uri $url -Method GET -ContentType "application/json" -Headers $headers -TimeoutSec $timeout -Verbose
Write-Host "[ps1] get all documents: $result" -ForegroundColor Yellow
foreach($item in $result){
Write-Host "[ps1] A: $($item.value.A[0])" -ForegroundColor DarkGray
#GET ETAG AND ID OF THE FIRST DOCUMENT
$etag = $item.value.__etag[0]
$id = $item.value.id[0]
break;
}
#PATCH DOCUMENT
$json = $jsonFile | ConvertFrom-Json
$json.A.A1 = 15
$json | Add-Member @{"id"= $id}
$json | Add-Member @{"__etag"= $etag}
$body = $json | ConvertTo-Json
$api = "api-version=3.1-preview.1"
$url = "$Uri/$Collection/_apis/ExtensionManagement/InstalledExtensions/$Publisher/$Extension/Data/Scopes/Default/Current/Collections/$Collection/Documents?$api"
$patch = Invoke-RestMethod -Uri $url -Method PATCH -ContentType "application/json" -Headers $headers -Body $body -TimeoutSec $timeout -Verbose
Write-Host "[ps1] patch document: $patch" -ForegroundColor Yellow
Write-Host "[ps1] patched A: $($patch.A)" -ForegroundColor Gray
#REMOVE ALL DOCUMENTS
Write-Host "[ps1] documents to remove: $($result.count)"
for($i = 0; $i -lt $result.count; $i++){
$id = $result.value[$i].id
$api = "api-version=3.1-preview.1"
$url = "$Uri/$Collection/_apis/ExtensionManagement/InstalledExtensions/$Publisher/$Extension/Data/Scopes/Default/Current/Collections/$Collection/Documents/$($result.value[$i].id)?$api"
Invoke-RestMethod -Uri $url -Method DELETE -ContentType "application/json" -Headers $headers -TimeoutSec $timeout -Verbose
Write-Host "[ps1] delete document: $id" -ForegroundColor Red
}