How can I call pre-release Rest Apis from an Azure DevOps extension?

拟墨画扇 提交于 2020-01-06 04:50:07

问题


It seems REST clients for preview versions of the Azure DevOps REST APIs do not get published. So the API is there and works, but a REST client is not.

So how can I access e.g. the 6.0 (as of now: preview) feature pagesBatch from an Azure DevOps extension?


回答1:


Because it's a preview API and not included yet in the SDK you can do a pure HTTP Get/Post Rest API calls with Typescript, for example:

Install:

npm install --save request
npm install --save request-promise-native

Then in the extension:

import * as request from "request-promise-native";

(async () => {

  const url = 'https://dev.azure.com/fabrikam/e5e9e01e-801a-47eb-80bb-0ad24f448abe/_apis/wiki/wikis/sampleProjectWiki/pagesBatch';
  const result = await request.post(url, access_token: 'your-pat', body: JSON.stringify({pageViewsForDays: '30', continuationToken: '1', top: '5', 'content_type': 'application/json' }}}) );


 })()

Or use another Rest API methods, there are many ways to do it on Typescript.



来源:https://stackoverflow.com/questions/59537592/how-can-i-call-pre-release-rest-apis-from-an-azure-devops-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!