### Perform GET Operations with C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-projects-api Examples demonstrating how to retrieve data from the Targetprocess API using HttpClient with and without basic authentication. ```C# 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 Users assigned to Project with ID#2 string query = "projects/2/ProjectMembers?where=(User.IsActive eq 'true')include=[User]&take=1000"; //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); } } } } ``` ```C# 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 Project with ID#13 string query = "projects/206?include=[Id,Name,EntityState]&append=[UserStories-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); } } } } ``` -------------------------------- ### Authenticate and Query User Stories in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-userstories-api Examples demonstrating how to perform authenticated GET requests to the User Stories API using HttpClient. ```csharp 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); } } } } ``` ```csharp 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); } } } } ``` -------------------------------- ### POST /api/v1/projects Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-projects-api Creates or updates a project. The example demonstrates assigning a user to a project. ```APIDOC ## POST /api/v1/projects ### Description Creates or updates a project. This endpoint accepts a JSON payload containing project details. ### Method POST ### Endpoint https://restapi.tpondemand.com/api/v1/projects ### Request Body - **Id** (integer) - Required - The ID of the project to update. - **ProjectMembers** (array) - Optional - A list of project members to assign. ### Request Example { "Id": 229, "ProjectMembers": [ { "User": { "Id": 6 } } ] } ``` -------------------------------- ### Authenticate and Query Bugs in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-bugs-api Examples demonstrating how to perform authenticated GET requests to the Bugs API using HttpClient. ```csharp 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 bugs which are not closed yet string query = "bugs?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); } } } } ``` ```csharp 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 bugs closed last week string lastMonday = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).ToString("yyyy-MM-dd"); string query = "bugs?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); } } } } ``` -------------------------------- ### Create a Requester via POST in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-requesters-api Examples demonstrating how to send a POST request to the Requesters endpoint using HttpClient. ```C# 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 Requester string query = "requesters"; HttpContent payload = new StringContent("{\"FirstName\":\"Jane\",\"LastName\":\"White\",\"Email\":\"jane@gmail.com\"}", 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); } } } } ``` ```C# 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 Requester string query = "requesters"; HttpContent payload = new StringContent("{\"FirstName\":\"Jane\",\"LastName\":\"White\",\"Email\":\"jane@gmail.com\"}", 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); } } } } ``` -------------------------------- ### Authenticate and Query Users in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-users-api Demonstrates how to perform authenticated GET requests to the Targetprocess API using HttpClient. ```csharp 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; //find a User by email string query = "users?where=(email eq 'teddy@targetprocess.com')"; //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); } } } } ``` ```csharp 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; //find a User by email string query = "users?where=(email eq 'teddy@targetprocess.com')"; //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); } } } } ``` -------------------------------- ### POST Request Examples for Generals Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-generals-api Common API queries for adding comments or tags to specific items. ```HTTP POST to `/api/v1/comments` payload `{"Description":"New comment","General":{"Id":194}}` ``` ```HTTP POST to `/api/v1/generals/194` payload `{"Tags":"urgent"}` ``` -------------------------------- ### Authenticate and Retrieve Epics in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-epics-api Examples demonstrating how to use HttpClient to fetch Epics using either a generated token or an access token. ```csharp 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 Epics which are not closed yet string query = "epics?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); } } } } ``` ```csharp 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 Epics closed last week string lastMonday = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).ToString("yyyy-MM-dd"); string query = "epics?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); } } } } ``` -------------------------------- ### Retrieve Assignables via C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-assignables-api Examples demonstrating how to fetch assignable data from the Targetprocess REST API using HttpClient. ```csharp 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 work items for project with ID#192 string query = "assignables?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); } } } } ``` ```csharp 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 work item ID#191 string query = "assignables/191?include=[Id,Name,EntityState]&append=[Comments-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); } } } } ``` -------------------------------- ### C# POST Request with Authentication Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-generals-api Examples demonstrating how to update an entity name using different authentication strategies. ```C# 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; //change name for item ID#224 string query = "generals/224"; HttpContent payload = new StringContent("{\"Name\":\"Research\"}", 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); } } } } ``` ```C# 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; //change name for item ID#224 string query = "generals/224"; HttpContent payload = new StringContent("{\"Name\":\"Research\"}", 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); } } } } ``` ```C# 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; //change name for item ID#224 string query = "generals/224"; HttpContent payload = new StringContent("{\"Name\":\"Research\"}", 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); } } } } ``` -------------------------------- ### Delete Project via C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-projects-api Examples demonstrating how to delete a project with ID 234 using different authentication strategies. ```csharp 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; //delete Project ID#234 string query = "projects/234"; //using access token generated at Personal Details page (Access Tokens tab) query += "?access_token=MTpoUmx4WW1LTzF6dlkvbUN1dTZIclVBUFQyQ1Z0MkN6YnF6OHBETmRZN2kwPQ=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Project ID#234 string query = "projects/234"; //using a token generated at /api/v1/Authentication query += "?token=MTpGMjRERDMxODUzNDk1NjdFOTQ0NEY4NkFFOEJCMjkzMw=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Project ID#234 string query = "projects/234"; //using basic authentication (here 'admin' is login and 'admin' is password) string authentication = Convert.ToBase64String(Encoding.ASCII.GetBytes("admin:admin")); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", authentication); Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Project ID#234 string query = "projects/234"; //using no authentication will result in 401 Unauthorized response Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` -------------------------------- ### C# Access Token Authentication Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-userstories-api Example of using HttpClient in C# to authenticate with an access token and create a UserStory. ```C# 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 User Stories in a Project ID#2 string query = "userstories"; HttpContent payload = new StringContent("{\"Name\":\"New Story\",\"Project\":{\"Id\":2}}", 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); } } } } ``` -------------------------------- ### Authenticate with Token in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-assignables-api Demonstrates how to perform a GET request to the Assignables endpoint using a token generated via the Authentication API. ```csharp 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 work items which are not closed yet string query = "assignables?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); } } } } ``` -------------------------------- ### GET /api/v1/projects Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-projects-api Retrieves a list of projects from Targetprocess. Supports filtering, sorting, and field inclusion. ```APIDOC ## GET /api/v1/projects ### Description Retrieves a collection of projects. Supports query parameters for filtering, limiting results, and including related fields. ### Method GET ### Endpoint /api/v1/projects ### Query Parameters - **where** (string) - Optional - Filter expression (e.g., CreateDate gte '2017-01-01') - **take** (integer) - Optional - Number of records to retrieve - **include** (string) - Optional - Fields or collections to include in the response - **orderby** (string) - Optional - Field to sort results by - **token** (string) - Optional - Authentication token - **access_token** (string) - Optional - Access token for authentication ``` -------------------------------- ### Retrieve Tasks via REST API Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-tasks-api Example queries for fetching Tasks with specific filters, field inclusions, and collection handling. ```text /api/v1/tasks?include=[Id,Name,Comments]&take=100&innertake=1000 ``` ```text /api/v1/comments?where=(General.EntityType.Name eq 'Task')&include=[Id,Name,General]&take=1000 ``` ```text /api/v1/tasks?where=(CreateDate gte '2017-01-01')and(CreateDate lte '2017-01-31')&take=1000 ``` ```text /api/v1/tasks?where=(EndDate gte '2017-01-01')and(EndDate lte '2017-01-31')&take=1000 ``` ```text /api/v1/tasks?where=(Iteration.IsCurrent eq 'true')&take=1000 ``` ```text /api/v1/tasks?where=(Release.IsCurrent eq 'true')&take=1000 ``` ```text /api/v1/tasks?where=(Owner.Id eq 1)&include=[Id,Name,CreateDate,StartDate,EndDate,EntityState]&take=1000 ``` -------------------------------- ### Perform GET request with Basic Authentication in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-bugs-api Uses HttpClient to retrieve bugs for a specific project using Basic authentication credentials. ```csharp 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 bugs for project with ID#192 string query = "bugs?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); } } } } ``` -------------------------------- ### Delete UserStory via C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-userstories-api Examples demonstrating how to delete a UserStory using different authentication strategies with HttpClient. ```csharp 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; //delete User Story ID#205 string query = "userstories/205"; //using access token generated at Personal Details page (Access Tokens tab) query += "?access_token=NjplaXdQeTJDOHVITFBta0QyME85QlhEOWpwTGdPM2V6VjIyelZlZ0NKWG1RPQ=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete User Story ID#205 string query = "userstories/205"; //using a token generated at /api/v1/Authentication query += "?token=Njo4OTIyQzkzN0M5NEY3NzNENDIyNTM2RDU3MTMwMTMwOA=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete User Story ID#205 string query = "userstories/205"; //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.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete User Story ID#205 string query = "userstories/205"; //using no authentication will result in 401 Unauthorized response Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` -------------------------------- ### Delete Work Item via C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-generals-api Examples demonstrating how to send a DELETE request to the Targetprocess API using HttpClient. ```csharp 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; //delete work item ID#207 string query = "generals/207"; //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.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete work item ID#207 string query = "generals/207"; //using no authentication will result in 401 Unauthorized response Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` -------------------------------- ### Retrieve User via GET with Basic Authentication in C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-users-api Uses HttpClient to query the API for a user by email with Basic authentication headers. ```csharp 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; //find a User by email string query = "users?where=(email eq 'teddy@targetprocess.com')"; //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); } } } } ``` -------------------------------- ### Delete Requester via C# Source: https://www.ibm.com/docs/en/targetprocess/tp-dev-hub/saas?topic=reference-requesters-api Examples demonstrating how to delete a Requester using different authentication strategies in C#. ```csharp 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; //delete Requester ID#21 string query = "requesters/21"; //using access token generated at Personal Details page (Access Tokens tab) query += "?access_token=NjplaXdQeTJDOHVITFBta0QyME85QlhEOWpwTGdPM2V6VjIyelZlZ0NKWG1RPQ=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Requester ID#21 string query = "requesters/21"; //using a token generated at /api/v1/Authentication query += "?token=Njo4OTIyQzkzN0M5NEY3NzNENDIyNTM2RDU3MTMwMTMwOA=="; Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Requester ID#21 string query = "requesters/21"; //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.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ``` ```csharp 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; //delete Requester ID#21 string query = "requesters/21"; //using no authentication will result in 401 Unauthorized response Console.WriteLine("Posting to " + query); HttpResponseMessage response = client.DeleteAsync(query).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response.Content.ReadAsStringAsync().Result); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } } } } ```