Explore Team Foundation Server (TFS) REST API

Source: Internet
Author: User

Rest is a simple and convenient web service that can provide remote services to a variety of client programs through remote communication based on HTTP protocol, greatly improving the scalability of the server system.

Microsoft announced the provision of Rest API remote access from Team Foundation Server starting with version 2015, as early as 2014, when Team foudation Service (VSO) released the Rest API's interface program. With Test, TFS provides a lightweight way for multiple clients and applications to enable rapid data exchange with TFS servers. Developers can run client programs on Windows, Andriod, iOS and other devices to access TFS, implement code Check-in, project planning and tracking, and so on, almost all of the work that TFS clients can accomplish.

Until the rest API is launched, developers can only implement TFS extensions through the. NET API or the Java API. Now with the rest API, customers can expand on any platform and terminal, especially devices such as mobile phones. Different developers can use their familiar development tools and development language to invoke the rest API to enable integration of different systems with TFS.

Here I take the most common JavaScript example, combining jquery, with the most common examples of work item operations to illustrate how to use the Rest API interface of TFS.

Before you begin, you can get a description of all of TFS's APIs through this link https://www.visualstudio.com/en-us/integrate/api/overview.

1. Create a work item

Note The following example program uses jquery to read the information that is configured in the HTML control, such as the address of TFS, team project name, account and password, and so on.

function Newwit () {
var Tfsurl = $ ("#TFSCollection"). Val () + $ ("#ProjectName"). Val () + "/_apis/wit/workitems/$" + $ ("#WorkItemType"). Val () + "api-version=1.0";
A complete example of a URL: https://{account}.visualstudio.com/defaultcollection/{project}/_apis/wit/workitems/${ Workitemtypename}?api-version={version}
$ (Tfsurl). Val (Tfsurl);
var Paradata = $ ("#ApiParas"). Val ();//Example: [{"OP": "Add", "path": "/fields/system.title", "value": "Work Item title"},{"OP": "Add", "Path": "/fields/system.assignedto", "Value": "TFSAdmin"}]
$ (Apiparas). Val (Paradata);
$.ajax ({
Url:tfsurl,
Type: "PATCH",
ContentType: "Application/json-patch+json",
Data:paradata,
Success:function (data) {
$ ("#ApiResult"). Val (json.stringify (data));
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
$ ("#ApiResult"). Val ("error:\n" + Errorthrown);
},
Username: $ ("#TFSUserName"). Val (),
Password: $ ("#TFSPassword"). Val ()
});
}

2. Modifying work Items

function Updatewit () {
var Tfsurl = $ ("#TFSCollection"). Val () + "_apis/wit/workitems/" + $ ("#WitId"). Val () + "? api-version=1.0";
$ (Tfsurl). Val (Tfsurl);
var Paradata = $ ("#ApiParas"). Val (); Example: [{"OP": "Add", "path": "/fields/system.title", "value": "Work Item title"},{"OP": "Add", "path": "/fields/system.assignedto "," value ":" TFSAdmin "}]
$ (Apiparas). Val (Paradata);
$.ajax ({
Url:tfsurl,
Type: "PATCH",
ContentType: "Application/json-patch+json",
Data:paradata,
Success:function (data) {
$ ("#ApiResult"). Val (json.stringify (data));
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
$ ("#ApiResult"). Val ("error:\n" + Errorthrown);
},
Username: $ ("#TFSUserName"). Val (),
Password: $ ("#TFSPassword"). Val ()
});
}

3. Add Work Item Links

function Updatewit () {
var Tfsurl = $ ("#TFSCollection"). Val () + "_apis/wit/workitems/" + $ ("#WitId"). Val () + "? api-version=1.0";
$ (Tfsurl). Val (Tfsurl);
var Paradata = $ ("#ApiParas"). Val (); Example: [{"OP": "Add", "path": "/relations/-", "value": {"rel": "System.linktypes.dependency-forward", "url": "// Tfs2015cn:8080/tfs/abchinacollection/_apis/wit/workitems/17 "}}]
$ (Apiparas). Val (Paradata);
$.ajax ({
Url:tfsurl,
Type: "PATCH",
ContentType: "Application/json-patch+json",
Data:paradata,
Success:function (data) {
$ ("#ApiResult"). Val (json.stringify (data));
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
$ ("#ApiResult"). Val ("error:\n" + Errorthrown);
},
Beforesend:function (XHR) {
$ ("#ApiResult"). Val ("Loading ...");
},
Username: $ ("#TFSUserName"). Val (),
Password: $ ("#TFSPassword"). Val ()
});
}

4. Modify the Iteration Path

function Updatewit () {
var Tfsurl = $ ("#TFSCollection"). Val () + "_apis/wit/workitems/" + $ ("#WitId"). Val () + "? api-version=1.0";
$ (Tfsurl). Val (Tfsurl);
var Paradata = $ ("#ApiParas"). Val (); Example: [{"OP": "Add", "path": "/fields/system.title", "value": "Work Item title" User 2 "},{" OP ":" Add "," path ":"/fields/ System.IterationPath "," Value ":" cmmi\\ Iteration 0 "}]
$ (Apiparas). Val (Paradata);
$.ajax ({
Url:tfsurl,
Type: "PATCH",
ContentType: "Application/json-patch+json",
Data:paradata,
Success:function (data) {
$ ("#ApiResult"). Val (json.stringify (data));
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
$ ("#ApiResult"). Val ("error:\n" + Errorthrown);
},
Username: $ ("#TFSUserName"). Val (),
Password: $ ("#TFSPassword"). Val ()
});
}

Http://www.cnblogs.com/danzhang/ALM MVP Zhang Hongjun

Explore Team Foundation Server (TFS) REST API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.