dkmiller / tidbits

Short notes on stuff I have recently discovered / understood
1 stars 0 forks source link

Azure DevOps wiki page views API #36

Closed dkmiller closed 3 years ago

dkmiller commented 3 years ago

https://docs.microsoft.com/en-us/rest/api/azure/devops/wiki/page%20stats/get?view=azure-devops-rest-6.0

Reference: https://developercommunity.visualstudio.com/idea/379614/page-view-analytics-for-wiki.html?childToView=1186799#comment-1186799

dkmiller commented 3 years ago

Try:

from azure.identity import DefaultAzureCredential
import requests

cred = DefaultAzureCredential()

# GUID from: https://github.com/microsoft/azure-devops-auth-samples/blob/master/ManagedClientConsoleAppSample/Program.cs .
access_token = cred.get_token("499b84ac-1321-427f-aa17-267ca6975798/.default").token

headers = {"Authorization": f"Bearer {access_token}"}

r = requests.get("https://dev.azure.com/msdata/Vienna/_apis/wiki/wikis", headers=headers)

# TODO: use JSONPath instead.
wiki_id = [w["id"] for w in r.json()["value"] if w["name"] == "aml-1p-onboarding"][0]

# TODO: what next? How to get page IDs?