我正在尝试将我的第一个请求写到Monday.com,但是我不明白为什么我的请求会返回到"StatusCode: NotAcceptable“。我尝试过几种不同的方法来发送查询,但不确定这就是问题所在。以前有没有人这样做过,或者以前见过这个问题?我改变了我的boardI,也尝试了一个Get和Post。谢谢你的帮助!
static async Task Main(string[] args)
{
//ReadXMLFileForSettings.ReadConfig();
var client = new RestClient("https://api.monday.com/v2/");
RestRequest request = new RestRequest() { Method = Method.Post };
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", $"{APIToken}");
request.AddParameter(new JsonParameter("query", "query { boards(ids: 1234) { owner{ id } columns { title type } } }"));
//request.AddParameter("query", "query { boards(ids: 1578294790) { owner{ id } columns { title type } } }");
//request.AddJsonBody(new
//{
// query = "query { boards(ids: 1578294790) { owner{ id } columns { title type } } }"
//});
var response = await client.ExecuteAsync(request);
var responseWorkloads = JObject.Parse(response.Content).SelectToken("boards");
var responseWorkloadsItems = responseWorkloads.SelectToken("items");
foreach (JObject value in responseWorkloadsItems)
{
foreach (var property in value.Properties())
{
Logging.WriteToLog(property.Name);
Logging.WriteToLog(property.Value.ToString());
}
}
}发布于 2022-01-15 01:08:55
试试这个:
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.monday.com/v2/");
request.Headers.Authorization = new AuthenticationHeaderValue(token);
string json =
System.Text.Json.JsonSerializer.Serialize(
new
{
query = "{ boards(ids: 1234) { owner{ id } columns { title type } } }"
}
);
request.Content = new StringContent(json,
Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var responseText = await response.Content.ReadAsStringAsync();
// TODO handle responseUPD: RestSharp
var client = new RestClient("https://api.monday.com/v2/");
RestRequest request = new RestRequest() { Method = Method.Post };
request.AddHeader("Authorization", token);
//Here is the main problem:
//Idk why, but RestSharp adds the default accept header with value
//application/json, text/json, text/x-json, text/javascript, *+json, application/xml, text/xml, *+xml, *
// I didn't asked it for that!
request.AddHeader("Accept", "*/*");
string json =
System.Text.Json.JsonSerializer.Serialize(
new
{
query = "{ boards(ids: 1234) { owner{ id } columns { title type } } }"
}
);
request.AddStringBody(json, "application/json");
var response = await client.ExecuteAsync(request);
// TODO handle response发布于 2022-01-15 11:11:34
这里的问题是,周一API不是JSON,而是GraphQL。使用它的最佳方法是为.NET找到一个.NET客户端,例如https://github.com/graphql-dotnet/graphql-client
发布于 2022-01-16 16:16:35
通过将它更改为HttpClient就能使它工作。以下是代码:
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.monday.com/v2/");
request.Headers.Authorization = new AuthenticationHeaderValue(MondayApiKey);
string json =
System.Text.Json.JsonSerializer.Serialize(
new
{
query = "{boards(limit:1){id name}}"
}
);
request.Content = new StringContent(json,Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var responseText = await response.Content.ReadAsStringAsync();https://stackoverflow.com/questions/70717201
复制相似问题