C# .NET 使用 Trello REST 更新卡片上的自定义字段项目 API
C# .NET Update Custom Field item on Card using Trello REST API
我正在使用 c# 中的 .NET 创建一个应用程序以在 Trello 看板上创建卡片,但我无法更新自定义字段。
我已经搜索了 API 文档和互联网,但无法正常工作。
我用来更新卡片上自定义字段值的代码如下:
private static async Task<String> PutCustomFieldsAsync(string Url, string jsonContent)
{
using (var httpClient = new HttpClient())
{
var response = await httpClient.PutAsync(Url, new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json"));
json = await response.Content.ReadAsStringAsync();
};
return json;
}
变量的值如下:
Url: "https://api.trello.com/1/cards/6...3fe/customField/5...bb9/item?key=4...f&token=e...6"
jsonContent: "{"Value":{"text":"test"}}"
当我在 Trello 上手动设置字段然后获取卡片自定义字段时,出现的 JSON 具有以下数据:
{
"id": "6...c66",
"value": {
"text": "teste"
},
"idCustomField": "5...bb9",
"idModel": "6...3fe",
"modelType": "card"
}
由于“自定义字段类型的值无效”,我得到的响应是“400 错误请求”。
任何人都可以帮助我让它工作吗?
谢谢。
如果有人遇到同样的问题,我设法让 trello 使用以下代码更新自定义字段:
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Collections;
private static async Task<String> PutCustomFieldsAsync(string CardId, string CustomFieldId, string AppKey, string Token, string Value)
{
string json = null;
Hashtable tableAux= new Hashtable();
tableAux["text"] = value;
Hashtable table = new Hashtable();
table["value"] = tableAux;
string Url = String.Format("https://api.trello.com/1/cards/{0}/customField/{1}/item?key={2}&token={3}", CardId, CustomFieldId, AppKey, Token);
string jsonContent= JsonSerializer.Serialize(table);
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod(Method), Url))
{
request.Headers.TryAddWithoutValidation("Content - Type", "application/json");
request.Content = new StringContent(jsonContent);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
HttpResponseMessage response = httpClient.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
json = await response.Content.ReadAsStringAsync();
}
}
return json;
}
我正在使用 c# 中的 .NET 创建一个应用程序以在 Trello 看板上创建卡片,但我无法更新自定义字段。 我已经搜索了 API 文档和互联网,但无法正常工作。
我用来更新卡片上自定义字段值的代码如下:
private static async Task<String> PutCustomFieldsAsync(string Url, string jsonContent)
{
using (var httpClient = new HttpClient())
{
var response = await httpClient.PutAsync(Url, new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json"));
json = await response.Content.ReadAsStringAsync();
};
return json;
}
变量的值如下:
Url: "https://api.trello.com/1/cards/6...3fe/customField/5...bb9/item?key=4...f&token=e...6"
jsonContent: "{"Value":{"text":"test"}}"
当我在 Trello 上手动设置字段然后获取卡片自定义字段时,出现的 JSON 具有以下数据:
{
"id": "6...c66",
"value": {
"text": "teste"
},
"idCustomField": "5...bb9",
"idModel": "6...3fe",
"modelType": "card"
}
由于“自定义字段类型的值无效”,我得到的响应是“400 错误请求”。
任何人都可以帮助我让它工作吗?
谢谢。
如果有人遇到同样的问题,我设法让 trello 使用以下代码更新自定义字段:
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Collections;
private static async Task<String> PutCustomFieldsAsync(string CardId, string CustomFieldId, string AppKey, string Token, string Value)
{
string json = null;
Hashtable tableAux= new Hashtable();
tableAux["text"] = value;
Hashtable table = new Hashtable();
table["value"] = tableAux;
string Url = String.Format("https://api.trello.com/1/cards/{0}/customField/{1}/item?key={2}&token={3}", CardId, CustomFieldId, AppKey, Token);
string jsonContent= JsonSerializer.Serialize(table);
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod(Method), Url))
{
request.Headers.TryAddWithoutValidation("Content - Type", "application/json");
request.Content = new StringContent(jsonContent);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
HttpResponseMessage response = httpClient.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
json = await response.Content.ReadAsStringAsync();
}
}
return json;
}