Simple c# for adding an item to a board

I am trying to add a simple item to a board:
var helper = new MondayHelper();
string json = await helper.QueryMondayApiV2(“{"query": "{boards(limit:100){id name}}"}”);

string query = @"{""query"": ""mutation {create_item(board_id: 628989982, item_name: \""adding works\"", column_values: ""{\""Status\"": \""Done\""}"")  }"" }";
await helper.QueryMondayApiV2(query);

However I get a bad request. Sample works without column_values. All poiters are welcome.

Hi @ThomasSe,

Welcome to the community!

Just to confirm, are you using the MondaySDK? Or have your created your own function to perform a query/mutation?

Just by looking at the code snippet, my guess is that you have created your own function. monday has released an SDK that takes care of all the hard work for you, you simply need to add the query/mutation string and away you go.

Take a look at the SDK here GitHub - mondaycom/monday-sdk-js: Node.js and JavaScript SDK for developing over the monday.com platform

try {
        const mondayClient = initMondayClient();
        mondayClient.setToken(token);

        const query = `query($itemId: [Int], $columnIds: [String]) {
            items (ids: $itemId) {
              column_values(ids:$columnIds) {
                id
                type
                value
                text
              }
            }
          }`;
          const variables = { columnIds, itemId };
          const response = await mondayClient.api(query, { variables });

          return response.data.items[0].column_values
    } catch (err)  {
        console.log(err);
    }

This is a quick sample that I pulled from one of my functions.

Thanks very helpfull. Unfortuntly it is a JavaScript SDK and I am looking for a c# version.

If I do like this I get following error:
string query = @“{”“query”“: ““mutation {create_item(board_id: 628989982, group_id:"“new_group"”, item_name: "“adding works"”, column_values: "”{\"“long_text\"”: \"“Done\"”}"”) {id} }”" }";
var res = await helper.QueryMondayApiV2(query);

"{"error_code":"ColumnValueException","status_code":200,"error_message":"invalid value, please check our API documentation for the correct data structure for this column. https://monday.com/developers/v2#column-values-section\“,\“error_data\”:{\“column_value\”:\“Done\”,\“column_type\”:\“LongTextColumn\”}}”

Hey there @ThomasSe! @mitchell.hudson, thank you so much for jumping in here, you’re literally amazing :slight_smile:

I am not a C# developer myself by any means, but I did some digging within the forum and here is what I was able to find:

Based on the error code you are getting, it seems like you are trying to send data to a Long Text column that is not accepted by the platform. It seems to me like this could be caused by the quotation marks, as well as a lack of a “text” declare, although those could be caused by forum formatting:

image

I would recommend making ssure the value conforms with each column’s data structure. You can find out more about this in the documentation, as the link suggests. Here is the data structure that is provided ed within our documentation:

Long text column

To update the long text column, send a string up to 2000 characters with the key “text”.

Raw JSON - use this in your column values variables:

JSON.stringify({ “text”: “Sample text” });

JSON string - use this in the GraphiQL editor:

“{"text":"Sample text"}”

Let us know if this helps :slight_smile: We’re keeping our fingers crossed!

-Alex

Thanks for fast response - appreciated. To remove the c# part I have made a post man sample:

{
“query”: “mutation {create_item(board_id: 628989982, group_id:“new_group”, item_name: “adding works”, column_values:{“long_text”:{ “text”: “Sample text”}}) {id}}”
}

Above works without the column_values section. However with I get following error:
{
“errors”: [
{
“message”: “Parse error on “long_text” (STRING) at [1, 106]”,
“locations”: [
{
“line”: 1,
“column”: 106
}
]
}
],
“account_id”: 5992539
}

Also I see different ways with queries. Some is like:
query {
boards (ids: 157244624) {
owner {id}
columns {
title
type
}
}
}

And some is like mine as JSON: {“query”: …}. When do you use one over the other?

1 Like

@ThomasSe

Thank you for providing the code you are having issues with, that is a big help to put your issue into context :slight_smile:

If I recall correctly, all of the queries sent to our API have to be sent as a JSON string and a POST request. On the try-it-yourself page, that formatting is done automatically within the tool. I’ll double-check this with the team just to be sure.

That said, from what I am able to tell, the reason you are having issues with this column_values part of creating the item is related to formatting the values you are trying to send properly as a JSON string. I’ve just tried to create a version of your mutation myself and here’s what seems to work within the try it yourself environment:

Here is the exact code I’ve used:

mutation {create_item(
board_id: REPLACEWITHYOURBOARDID,
group_id: “REPLACEWITHYOURGROUPID”,
item_name: “adding works”,
column_values: “{ “long_text”: {“text”:“Sample text”}}”)
{id}
}

Let me know if this is helpful :slight_smile:

-Alex

Hi Alex,
Thanks a lot appreciated. I got it working in the “Try it your self” environment. Did not know that existed nifty little tool. Now I got that working I can start converting it to c#. Thanks a lot. It is kind of strange however that column_values expects a string value and not just a json object.

1 Like

@ThomasSe

I’m really glad I was able to help you here :slight_smile: That’s awesome!

I’m sure you will end up making lots of cool integrations and API calls in C#. If I’m not asking for too much, it would be an amazing help to the community to share a few working code examples, even if they’re simple. Sometimes a reference point is all a developer needs in order to plow through their issue, so it would be an awesome way to give back.

-Alex

I will add my findings, give me a week or two. Because your right we base heavily on Monday. But let me wee if I can do some wrappers.

1 Like

@ThomasSe amazing, thank you so much! Feel free to take as much time as you need, it’s all about sharing coming from a good place and in positive spirit :slight_smile:

If you end up getting more questions, I’d recommend starting a new topic at that point. I’m going to close this out for now!

-Alex