我已经整理了一些我的解决方案,我终于能够得到Zephyr的回复了,但当我知道它可用时,它给了我404响应。是否有其他人试图使用ZAPI报告测试数据?
秘密和访问密钥来自Zephyr添加的Jira页面。项目密钥来自Jira。这是我的代码和它给我的响应:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Jira.SDK.Domain;
using JWT;
namespace WebPortalUITests.Controllers
{
[TestClass]
public class Reporting
{
static string User = "My.User.Name";
static string Password = "My.Password";
static string jiraBaseUrl = "https://mycompany.atlassian.net/";
static string zephyrBaseUrl = "https://prod-api.zephyr4jiracloud.com/connect";
static string Secret = "P1oihENe5PLUS_THE_REST_OF_MY_SECRET";
static string AccessKey = "amlyYTox_PLUS_THE_REST_OF_MY_KEY";
public async Task<bool> CycleExists(string Name)
{
//connect to Jira to get project and version IDs using the Jira.SDK library
Jira.SDK.Jira jira = new Jira.SDK.Jira();
jira.Connect(jiraBaseUrl, User, Password);
Project webPortal = jira.GetProject("WP");
long id = webPortal.ID;
long version = webPortal.ProjectVersions.Last<ProjectVersion>().ID;
//format the Zephyr request and use it to generate a JWT
string request = "/connect/public/rest/api/1.0/cycles/search?versionId=" + version + "&projectId=" + id;
string finalAPI = zephyrBaseUrl + request;
string token = JsonWebToken.Encode(finalAPI, Secret, JwtHashAlgorithm.HS256);
//put the JWT and the accesskeys in the header and request the info
using (var httpClient = new HttpClient { BaseAddress = new Uri(zephyrBaseUrl)})
{
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "JWT "+token);
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("zapiaccesskey", AccessKey);
using (var response = httpClient.GetAsync(string.Format(request)).Result)
{
string responseData = await response.Content.ReadAsStringAsync();
}
return true;
}
}
}
}