gpt4 book ai didi

c#-4.0 - 如何使用 restsharp 通过 rest api 更新 jira 问题摘要

转载 作者:行者123 更新时间:2023-12-04 04:49:22 25 4
gpt4 key购买 nike

我一直在使用 jira rest api 来最终替换我在使用 4.0 .net 框架的 c# 应用程序中的 soap 实现。我也在使用 restsharp。

虽然我没有遇到问题或搜索其他 API 的问题,但我一直在努力更新 jira 问题。这些是我的执行方法,它们可以很好地获取或搜索 jira 问题。我在调用 SetJiraIssue 时收到的常见错误消息如下 {"errorMessages":["one of 'fields' or 'update' required"],"errors":{}}。

如果我将一个简单的 JSOn 字符串 exeample(string jSonContent = @"{""Fields"":{""summary"":""testing summary update""}}") 传递给请求的正文,然后它提示没有构造函数。

有人知道我做错了什么吗?欢迎提出意见和建议

  private string Execute(RestRequest request)
{
var client = new RestClient(_jiraUrl);

client.Authenticator = new HttpBasicAuthenticator(_accountId, _password);
request.AddParameter("AccountSid", _accountId, ParameterType.UrlSegment);
var response = client.Execute(request);

if (response.ErrorException != null)
{
const string message = "Error retrieving response. Check inner details for more info.";
var jiraManagerException = new ApplicationException(message, response.ErrorException);
throw jiraManagerException;
}

return response.Content;

}

/// <summary>
/// Executes a jira rest call and retuns the response if any as a business object.
/// </summary>
/// <typeparam name="T">Type of the return type for deserialization.</typeparam>
/// <param name="request">THe reste request.</param>
/// <returns></returns>
private T Execute<T>(RestRequest request) where T : new()
{
var client = new RestClient(_jiraUrl);
client.Authenticator = new HttpBasicAuthenticator(_accountId, _password);
request.AddParameter("AccountSid", _accountId, ParameterType.UrlSegment);
var response = client.Execute<T>(request);

if (response.ErrorException != null)
{
const string message = "Error retrieving response. Check inner details for more info.";
var jiraManagerException = new ApplicationException(message, response.ErrorException);
throw jiraManagerException;
}

return response.Data;
}


public void SetJiraIssue(string issueKey, JiraIssue j)
{
RestRequest request = new RestRequest("issue/{key}", Method.PUT);
request.AddUrlSegment("key", issueKey);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-type", "application/json");
j.Summary = "modifiying this issue";


request.AddBody(j);

var response = Execute(request);
Console.WriteLine(response);
}

最佳答案

我终于找到了一种让它工作的方法,这并不完全是我所期望的或希望它工作的方式,但这是我找到的唯一方法。希望这对其他人有用

public void SetJiraIssue(string issueKey, JiraIssue j)
{
RestRequest request = new RestRequest("issue/{key}", Method.PUT);
request.AddUrlSegment("key", issueKey);
request.RequestFormat = DataFormat.Json;

string jSonContent = @"{""fields"":{""summary"":""test changing summary""}}";
request.AddParameter("application/json", jSonContent, ParameterType.RequestBody);

var response = Execute(request);
Console.WriteLine(response);
}

关于c#-4.0 - 如何使用 restsharp 通过 rest api 更新 jira 问题摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17664368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com