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