/// <summary> /// Retrieves an issue, updates the Priority, and /// submits it back /// </summary> /// <param name="accessToken"> /// accessToken to use for the request /// </param> static async Task UpdateIssuePriorityExample(AccessToken accessToken) { try { // Gets the issue int issueID = 1; var url = projectName + "/issues/" + issueID + "?fields=Priority"; var request = new HttpRequestMessage(HttpMethod.Get, url); SetRequestAccessToken(ref request, accessToken); Issue issue = await SendRequest<Issue>(request); // Updates the Priority field and saves the issue if (issue != null) { // Updates the Priority field foreach (Field field in issue.fields) { if (field.label == "Priority") { field.menuItem.label = "Before Beta"; break; } } // Saves the issue UpdateIssuesResponse response = await SaveIssue(accessToken, issue); System.Diagnostics.Debug.WriteLine("Issue Updated"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
/// <summary> /// Adds a new Found by record by getting an issue, adding /// the record, and submitting it back to the server. /// </summary> /// <param name="accessToken"> /// The accessToken to use for the request /// </param> static async Task AddReportedByRecordExample(AccessToken accessToken) { try { // Gets the issue int issueID = 1; // IS-11 var url = projectName + "/issues/" + issueID + "?expand=foundByRecords"; var request = new HttpRequestMessage(HttpMethod.Get, url); SetRequestAccessToken(ref request, accessToken); Issue issue1 = await SendRequest<Issue>(request); if (issue1 != null) { // Creates a new Found by record FoundByRecord newRecord = new FoundByRecord(); newRecord.foundBy = new User(); newRecord.foundBy.username = "******"; newRecord.dateFound = DateTime.UtcNow.ToString("yyyy-MM-dd"); newRecord.description = new TextField(); newRecord.description.text = "This is a new record added by AddReportedByRecordExample"; newRecord.versionFound = "1.0"; // Adds the record to the Found by records array FoundByRecord[] foundbyRecords = issue1.foundByRecords.foundByRecordsData; Array.Resize(ref foundbyRecords, foundbyRecords.Length + 1); foundbyRecords[foundbyRecords.Length - 1] = newRecord; issue1.foundByRecords.foundByRecordsData = foundbyRecords; UpdateIssuesResponse response = await SaveIssue(accessToken, issue1); System.Diagnostics.Debug.WriteLine("Added found by record"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
/// <summary> /// Saves an issue /// </summary> /// <param name="accessToken"> /// accessToken to use for the request /// </param> /// <param name="issue"> /// Issue JSON object to save /// </param> /// <returns> /// UpdateIssuesResponse JSON object /// </returns> static async Task<UpdateIssuesResponse> SaveIssue(AccessToken accessToken, Issue issue) { UpdateIssuesResponse responseBody = null; try { // Builds the request var url = projectName + "/issues/" + issue.id; var request = new HttpRequestMessage(HttpMethod.Put, url); SetRequestAccessToken(ref request, accessToken); StringContent stringContent = ConvertJsonObjectToStringContent<Issue>(issue); request.Content = stringContent; // Sends the request responseBody = await SendRequest<UpdateIssuesResponse>(request); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } return responseBody; }