Reputation: 147
I've been trying to retrieve Wiki URLs that are linked to a work item, and I've been able to retrieve the link between Work Item and Wiki Page. However, the link return is a VSTFS artifact link. Is it possible to retrieve the true URL with the query provided at this page of REST documentation, or does this only work for retrieving Work Items? I currently am receiving a TF400898 error when attempting with a TFS link similar to below.
vstfs:///Wiki/WikiPage/{vstfs identification string}
EDIT: Current Function
def getWikiURL(azureToken, parsedTFS):
# parsedTFS[0] == Project ID, parsedTFS[1] == Wiki Repo ID, parsedTFS[2] == [page1, page2, page3]
reqURL = "https://dev.azure.com/{Organization}/" + str(parsedTFS[0]) + "/_apis/_wiki/wikis/" + str(parsedTFS[1]) + "/pages/"
for pageDef in parsedTFS[2]:
reqURL = reqURL + "/" + pageDef
authorization = str(b64.b64encode(bytes(':'+azureToken, 'ascii')), 'ascii)
headers = {
'Accept': 'application/json',
'Authorization' : 'Basic '+authorization
}
r = requests.get(url=reqURL, headers=headers)
strR = r.content.decode("utf-8-sig")
print(strR)
print(strR) writes b'' to the console
Upvotes: 0
Views: 891
Reputation: 3185
Below is my wiki structure.
To get url to access to wiki3 page and use your function, below script should work as expected. Please run the command:
$ pip install requests
if you haven't installed the requests
library.
import base64 as b64
import requests
def getWikiURL(azureToken, parsedTFS):
#azureToken == PAT, parsedTFS[0] == Project ID, parsedTFS[1] == Wiki Repo ID, parsedTFS[2] == ["wiki1","wiki2","wiki3"]
reqURL = "https://dev.azure.com/{Organization}/" + str(parsedTFS[0]) + "/_apis/wiki/wikis/" + str(parsedTFS[1]) + "/pages/"
for pageDef in parsedTFS[2]:
reqURL = reqURL + "/" + pageDef
authorization = str(b64.b64encode(bytes(':'+azureToken, 'ascii')), 'ascii')
headers = {
'Accept': 'application/json',
'Authorization' : 'Basic '+authorization
}
r = requests.get(url=reqURL, headers=headers)
strR = r.content.decode("utf-8-sig")
print(strR)
getWikiURL("azureToken",["Project ID", "Wiki Repo ID", ["wiki1","wiki2","wiki3"]])
Upvotes: 1
Reputation: 3185
Use this Rest API: Work Items - Get Work Item, we can get the related wiki url to this work item with request url:
Get https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?$expand=Relations&api-version=6.0
From the response body, we can find the url of ArtifactLink looks like:
url": "vstfs:///Wiki/WikiPage/7e8XXXXXX3c79%2Ff2bb2XXXXXXe7431d5a61%2Fwiki1".
And then use this Rest API: Artifact Uri Query - Query to get linked work items to this wiki page.
To retrieve the true URL of VSTFS artifact link, please follow below steps. Please note that using PostMan to get the result. And using PAT authorization with full accesses.
vstfs:///Wiki/WikiPage/{project id}%2F{wiki repository id}%2F{wiki page name}
Get https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wiki repository id}/pages//{wiki page name}
Its response will tell you the wiki page’s id.
If you use nested pages (i.e. {parent page}/{sub page}), the request url is below:
Get https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wiki repository id}/pages//{parent page}/{sub page}
https://dev.azure.com/{organization}/{project}/_wiki/wikis/{wiki repository id}/{wiki page id}/{wiki page name}
Similarly, if you use nested pages (i.e. {parent page}/{sub page}), the url is below:
https://dev.azure.com/{organization}/{project}/_wiki/wikis/{wiki repository id}/{wiki page id}/{sub page}
Upvotes: 1