Example Application

This chapter of the documentation describes the TeamPusle .NET SDK and gives examples on how to integrate the TeamPulse service in your Windows-based applications. The TeamPulse .NET SDK is a wrapper around the TeamPulse REST services. It greatly simplifies the integration process and allows you to work with TeamPulse without having any knowledge of the REST services.

Here is a sample application that creates time entries for selected task.

1. Include TeamPulse SDK

You need to include the TeamPulse SDK in your project.

using Telerik.TeamPulse.Sdk;
using Telerik.TeamPulse.Sdk.Models;

2. Create an API client

Before you can make any requests you need to create an API client.

var settings = new TeamPulseAppSettings()
{
    SiteUrl = "TeamPulseUrl",
    Username = "UserName",
    Password = "Password",
    Domain = "Domain"
};

TeamPulseApp app = new TeamPulseApp(settings);

3. Authenticate

To authenticate you only need to execute the Login method of TeamPulseApp. (Read more about authentication)

app.Login();

4. Execute API calls

Now you can make calls throw the API to get or modify data.

WorkItem[] workitems = app.WorkItems.Get().results;
Team[] teams = app.Teams.Get().results;

Javascript example

Here is a sample application in javascript. You can see how to make API calls with ajax.

1. Authenticate

First you need to authenticate. (Read more about authentication). When you receive the accessToken you need to save it in order to execute further API calls.

$.ajax({
    url: "TeamPulseUrl" + '/Authenticate/WRAPv0.9',
    data: {
        wrap_client_id: 'uri:TeamPulse',
        wrap_username: "user",
        wrap_password: "password"
    },
    type: "POST",
    success: function (data) {              
        var accessToken = data.match(/wrap_access_token=(.*?)&/)[1];

        window.accessToken = decodeURIComponent(accessToken);
    }
});

2. Execute Get Call

After you have authenticated you can execute a call. You need to include your access token to the request, so the server knows who you are.

$.ajax({
    url: "TeamPulseUrl" + '/api/workitems',
    data: null,
    type: "GET",
    beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'WRAP access_token=' + window.accessToken); },
    success: function (data) {
        //data.totalResults - the count of all items
        //data.results - all items that are received
    }
});

3. Creating new items

Before you create new item you need to know all the fields that the items has. The call '/api/newworkitem' will return all the default values for your fields. Then you can change the fields and create new item.

var itemInfo;

//get fileds for new Bug item
$.ajax({ // Supported entity types - Story, Bug, Issue, Risk, Feedback, Task
    url: "TeamPulseUrl" + '/api/newworkitem',
    data: {
        type: 'Bug',
        projectId: 1
    },
    type: "POST",
    beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'WRAP access_token=' + window.accessToken); },
    success: function (data) {
        itemInfo = data;
    }
});

var changes = [];

//Depending of the item type some of the properties are requered and you may have to fill them in.
itemInfo.fields.Name = user + '\'s bug';
$.each(itemInfo.fields, function (name, v) {
    changes.push({
        name: name,
        oldValue: null,
        newValue: v
    });
});

//create new item
$.ajax({
    url: "TeamPulseUrl" + '/api/workitems',
    data: JSON.stringify({
        id: itemInfo.fields.EntityID,
        type: itemInfo.fields.EntityType,
        projectId: itemInfo.fields.ProjectID,
        fields: changes
    }),
    contentType: 'application/json; charset=utf-8',
    type: "POST",
    beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'WRAP access_token=' + window.accessToken); },
    success: function (data) {
        //data - the newly created item
    }
});

4. Updating items

To edit an item you don't have to send all the fields of the item. You only need to send the changed ones, and only they will be updated.

var changes = [{
    name: 'name',
    oldValue: itemInfo.fields.name,
    newValue: "new name"
}];

itemInfo.fields.Name = changes[0].newValue;

$.ajax({
    url: "TeamPulseUrl" + '/api/workitems/',
    data: JSON.stringify({
        id: itemInfo.fields.EntityID,
        type: itemInfo.fields.EntityType,
        fields: changes
    }),
    contentType: 'application/json; charset=utf-8',
    type: "PUT",
    beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'WRAP access_token=' + window.accessToken); },
    success: function (data) {
        //data - the updated item
    }
});