0

我正在尝试向 Monday.com 写我的第一个请求,但无法弄清楚为什么我的请求返回“StatusCode:NotAcceptable”。我尝试了几种不同的方法来发送查询,但不确定这是问题所在。有没有人这样做过或以前见过这个问题?我改变了我的董事会我还尝试了获取和发布。谢谢你的帮助!

    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());
            }
        }
    }
4

3 回答 3

1

试试这个:

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 response

UPD:休息夏普

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-15T01:08:55.990 回答
1

这里的问题是 Monday API 不是 JSON API,而是 GraphQL。使用它的最佳方法是为 .NET 找到 GraphQL 客户端,例如https://github.com/graphql-dotnet/graphql-client

于 2022-01-15T11:11:34.963 回答
0

能够通过将其更改为 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();
于 2022-01-16T16:16:35.960 回答