Get collection of User Stories

👍

More information

📘

Options for working with inner collections

If you'd like to get an inner collection there is an option to either include it into the list of retrieved fields, or to query this collection directly:

  • /api/v1/userstories?include=[Id,Name,Tasks]&take=100&innertake=1000
  • /api/v1/tasks?include=[Id,Name,UserStory]&take=1000

We recommend using the second approach.

Here are some popular queries:
  • get Stories created last months:
    /api/v1/userstories?where=(CreateDate gte '2017-01-01')and(CreateDate lte '2017-01-31')&take=1000

  • get Stories closed last months:
    /api/v1/userstories?where=(EndDate gte '2017-01-01')and(EndDate lte '2017-01-31')&take=1000

  • get Stories in the current iteration:
    /api/v1/userstories?where=(Iteration.IsCurrent eq 'true')&take=1000

  • get Stories in the current release:
    /api/v1/userstories?where=(Release.IsCurrent eq 'true')&take=1000

  • get Stories created by user ID#1:
    /api/v1/userstories?where=(Owner.Id eq 1)&include=[Id,Name,CreateDate,StartDate,EndDate,EntityState]&take=1000

using System;
using System.Net;
using System.Net.Http;

namespace REST.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://restapi.tpondemand.com/api/v1/");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            //get 5 oldest stories which are not closed yet
            string query = "userstories?where=(EntityState.IsFinal eq 'false')&take=5&orderby=CreateDate&include=[Id,Name,EntityState]";

            //using a token generated at /api/v1/Authentication
            query += "&token=Njo4OTIyQzkzN0M5NEY3NzNENDIyNTM2RDU3MTMwMTMwOA==";
            Console.WriteLine("Pulling " + query);
            
            HttpResponseMessage response = client.GetAsync(query).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}
using System;
using System.Net;
using System.Net.Http;

namespace REST.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://restapi.tpondemand.com/api/v1/");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            //get stories closed last week
            string lastMonday = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).ToString("yyyy-MM-dd");
            string query = "userstories?where=(EndDate gte '" + lastMonday + "')&include=[Id,Name,EndDate,TimeSpent]&take=1000";

            //using access token generated at Personal Details page (Access Tokens tab)
            query += "&access_token=NjplaXdQeTJDOHVITFBta0QyME85QlhEOWpwTGdPM2V6VjIyelZlZ0NKWG1RPQ==";
            Console.WriteLine("Pulling " + query);

            HttpResponseMessage response = client.GetAsync(query).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}
using System;
using System.Net;
using System.Net.Http;
using System.Text;

namespace REST.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://restapi.tpondemand.com/api/v1/");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            //get stories for project with ID#192
            string query = "userstories?where=(Project.Id eq 192)&take=1000&include=[Id,Name,EntityState]";

            //using basic authentication (here 'John' is login and '123' is password)
            string authentication = Convert.ToBase64String(Encoding.ASCII.GetBytes("John:123"));
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authentication);
            Console.WriteLine("Pulling " + query);

            HttpResponseMessage response = client.GetAsync(query).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}
using System;
using System.Net;
using System.Net.Http;

namespace REST.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://restapi.tpondemand.com/api/v1/");
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            //get a story with ID#191
            string query = "userstories/191?include=[Id,Name,EntityState]&append=[Bugs-count,Tasks-count]";

            //using no authentication will result in 401 Unauthorized response
            Console.WriteLine("Pulling " + query);

            HttpResponseMessage response = client.GetAsync(query).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}
Language
Click Try It! to start a request and see the response here!