0

I'm trying to write my first request to Monday.com and can't figure out why my request comes back "StatusCode: NotAcceptable". I've tried a few different methods to send the query but not sure that's the issue. Has anyone done this before or seen this issue before? I changed out my boardI and also tried a Get and Post. Thanks for any help!

    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());
            }
        }
    }
Meneghini
  • 147
  • 1
  • 1
  • 10

3 Answers3

1

Try this:

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: 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
Georgy Tarasov
  • 1,534
  • 9
  • 11
1

The issue here is Monday API is not a JSON API, it's GraphQL. The best way to use it is to find a GraphQL client for .NET, for example https://github.com/graphql-dotnet/graphql-client

Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
0

Was able to get it working by changing it to an HttpClient. Here is the code:

        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();
Meneghini
  • 147
  • 1
  • 1
  • 10