Hi,
I have these two methods, that are made to, with retreived data, push data into a board on monday using C#. When these two methods are called, they are surrounded with a try catch:
private string FormatDataForMonday(List<ResultItem> databaseData)
{
string mutationTemplate = @"mutation { create_item (board_id: bID, item_name: ""Test"", column_values: {JSON_DATA} ) {id} }";
string mutationQuery = mutationTemplate.Replace("bID", boardId);
var formattedData = new
{
items = databaseData.Select(dataItem => new
{
Site = dataItem.Site,
EwqPn = dataItem.EwqPn,
}).ToList()
};
// Serializing the entire formattedData, including both Site and EwqPn
string jsonFormattedData = Newtonsoft.Json.JsonConvert.SerializeObject(formattedData.items);
mutationQuery = mutationQuery.Replace("{JSON_DATA}", jsonFormattedData);
return mutationQuery;
}
public async Task<string> QueryMondayApiV2(string query)
{
byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(query);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MONDAY_API_URL);
request.ContentType = "application/json";
request.Method = "POST";
request.Headers.Add("Authorization", API_KEY);
using (Stream requestBody = request.GetRequestStream())
{
await requestBody.WriteAsync(dataBytes, 0, dataBytes.Length);
}
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
string responseBody = await reader.ReadToEndAsync();
Console.WriteLine("Request Payload:");
Console.WriteLine(query);
Console.WriteLine("Response Body:");
Console.WriteLine(responseBody);
return responseBody;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.ToString()}");
throw;
}
}
On the other hand, when I execute it, it catches an error 500. It seems like my JSON is correct, and the error would be triggered by something else. Here is the JSON that is created by FormatDataForMonday(). (The real board_id has been swapped for “boardId”) :
mutation { create_item (board_id: "boardId", item_name: "Test", column_values: [{"Site":"VTI","EwqPn":"1370C-0153A"}] ) {id} }
My board inside monday.com has all the columns that are needed to match what is in the JSON, but I feel like I’m overlooking something. Maybe someone has already ecountered something like this and could help me understand my problem.
Thank you !