Update existing or create a new Task

👍

More information

📘

To update a Task you have to know its ID.
To add a new Task you have to know ID of its Project.
If you'd like to connect a Task to some resources (EntityState, Team, Owner, etc.) you have to know their IDs.

Here are some popular queries:

  • change state for Task ID#219
    GET to /api/v1/tasks/219?include=[EntityState[NextStates]] (to know ID of the state)
    POST to /api/v1/tasks/219 payload {"EntityState":{"Id":87}}

  • set value "true" for custom field "Is internal" for Task ID#167
    POST TO /api/v1/tasks/167 payload {"CustomFields":[{"Name":"Is internal","Value":"true"}]}

  • create a Task for Story ID#194
    GET to /api/v1/userstories/194?include=[Project] (to know ID of the project)
    POST to /api/v1/tasks payload {"Name":"New task","Project":{"Id":2},"UserStory":{"Id":194}}

  • add a new comment for Task ID#219
    POST to /api/v1/comments payload {"Description":"New comment","General":{"Id":219}}

  • add time spent for Task ID#219
    POST to /api/v1/times payload {"Spent":2,"Remain":1,"Description":"Some work","Role":{"Id":1},"Assignable":{"Id":219}}

  • estimate Task ID#219 (5 story points for Developer, 2 story points for QA)
    POST to /api/v1/tasks/219 payload {"Roleefforts":[{"Role":{"Id":1},"Effort":5},{"Role":{"Id":9},"Effort":2}]}

  • add a Task to Story ID#194 in Project ID#2 and assign User ID#6 as Developer
    POST to /api/v1/tasks payload {"Name":"New task","Project":{"Id":2},"UserStory":{"Id":194},"Assignments":[{"GeneralUser":{"Id":6},"Role":{"Id":1}}]}

  • add a Task to Story ID#194 in Project ID#2, assign User ID#6 as Developer and estimate development work with 10 story points
    POST to /api/v1/tasks payload {"Name":"New task","Project":{"Id":2},"UserStory":{"Id":194},"Assignments":[{"GeneralUser":{"Id":6},"Role":{"Id":1}}],"Roleefforts":[{"Role":{"Id":1},"Effort":10}]}

  • set planned dates for several Task (ID#167 and ID#168)
    POST to /api/v1/tasks/bulk payload [{"Id":167,"PlannedStartDate":"2017-03-19","PlannedEndDate":"2017-08-29"},{"Id":168,"PlannedStartDate":"2017-03-19","PlannedEndDate":"2017-08-29"}]

  • create several Tasks for Story ID#194
    GET to /api/v1/userstories/194?include=[Project] (to know ID of the project)
    POST to /api/v1/tasks/bulk payload [{"Project":{"Id":192},"Name":"First Task","UserStory":{"Id":194}},{"Project":{"Id":192},"Name":"Second Task","UserStory":{"Id":194}}]

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;

            //create a new Task in Project ID#2
            string query = "tasks";
            HttpContent payload = new StringContent("{\"Name\":\"New Task\",\"Project\":{\"Id\":2},\"UserStory\":{\"Id\":16}}", Encoding.UTF8, "application/json");

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

            HttpResponseMessage response = client.PostAsync(query, payload).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;

            //create a new Task in Project ID#2
            string query = "tasks";
            HttpContent payload = new StringContent("{\"Name\":\"New Task\",\"Project\":{\"Id\":2},\"UserStory\":{\"Id\":16}}", Encoding.UTF8, "application/json");

            //using a token generated at /api/v1/Authentication
            query += "?token=Njo4OTIyQzkzN0M5NEY3NzNENDIyNTM2RDU3MTMwMTMwOA==";
            Console.WriteLine("Posting to " + query);

            HttpResponseMessage response = client.PostAsync(query, payload).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;

            //create a new Task in Project ID#2
            string query = "tasks";
            HttpContent payload = new StringContent("{\"Name\":\"New Task\",\"Project\":{\"Id\":2},\"UserStory\":{\"Id\":16}}", Encoding.UTF8, "application/json");

            //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("Posting to " + query);

            HttpResponseMessage response = client.PostAsync(query, payload).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;

            //create a new Task in Project ID#2
            string query = "tasks";
            HttpContent payload = new StringContent("{\"Name\":\"New Task\",\"Project\":{\"Id\":2},\"UserStory\":{\"Id\":16}}", Encoding.UTF8, "application/json");

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

            HttpResponseMessage response = client.PostAsync(query, payload).Result;
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }
        }
    }
}

📘

Adding or updating several Tasks at once

You can operate with several Tasks at once by using /api/v1/tasks/bulk endpoint.

Language
Click Try It! to start a request and see the response here!