C# Create_Item with Column_Values leads to (500) Internal Server Error

Hello,

I have scoured posts about the subject yet cannot find a suitable answer.

I am trying to create items using the API in C# with already populated columns.

I can, using the following query, make items with no information other than the title :
"{\"query\":\"mutation{ create_item(board_id: XXXXXXXXXX, group_id: XXXXX, item_name: XXXX){ id} }\"}"

However, adding column_values returns the Internal Server Error, even if it is empty.

I have tried the following methods, just to show a few (None of them have worked of course) :

  • "{\"query\":\"mutation{ create_item(board_id: XXXXXXXXXX, group_id: XXXXX, item_name: XXXX, column_values: \"{}\"){ id} }\"}"
  • "{\"query\":\"mutation{ create_item(board_id: XXXXXXXXXX, group_id: XXXXX, item_name: XXXX, column_values: \"{\"text\":\"151\",\"numbers\":\"1\"}\"){ id} }\"}"
  • {\"query\":\"mutation{ create_item(board_id: XXXXXXXXXX, group_id: XXXXX, item_name: XXXX, column_values: "{\"status\": {\"label\":\"Sign-Up\"}}"){ id} }\"}

Sorry if the formatting is hard to read.

I also tried with variables. All attempts so far have failed.

Thank you in advance.

hi @Will
Welcome to the community. From your list of 3 the first 2 are incorrect because you are escaping the initial string. The third one looks correct to me but are you sure:

  • status is the columnId (not the column name
  • “Sign-Up” is an existing label for that status column

Anyhow the correct syntax is found at Status and should read:

mutation {
  change_multiple_column_values(item_id:11111, board_id:22222, column_values: "{\"status15\" : {\"label\" : \"Done\"}}") {
    id
  }
}

Hey @Will

Hmm, that does look a bit odd!

I would suggest taking a look here:

C# Create Item in example
Simple C# for adding an item to a board
Connecting C# to monday.com

Perhaps this StackOverflow thread can be helpful:

StackOverflow - JSON.stringify equivalent in C#

I would recommend avoiding escaping manually, where possible. This can be error-prone and an unsustainable solution in the long-run. Using functions that do that work for you can save you a ton of time :slight_smile:

I hope this helps! Thank you so much for your input too, @basdebruin! You’re always really helpful.

-Alex

Thank you @basdebruin

After checking, status is the columnId and I changed “Sign-Up” to “Done”, which is an existing label.

However, it did not work. Creating an item following the format still returns Internal Server Error.

Trying to update an item using this query also does not work, returning the same Internal Server Error error :

"{\"query\":\"mutation{ change_multiple_column_values(item_id:XXXX, board_id:XXXX, create_labels_if_missing: true, column_values: \"{\"status\" : {\"label\" : \"Done\"}}\"){ id} }\"}"

As for the first part, the function to call the API requires a string, which is why my first two options have quotes. I merely forgot to copy them for the third one. Is that what you meant by “escaping the initial string”? Sorry for the confusion.

And thank you @AlexSavchuk

I had checked those three links, but the StackOverflow one was promising… sadly it didn’t help.

I’m assuming I did something wrong, but I’m not sure what. I based myself on the API Quickstart Guide in Javascript, substituting stringify with its equivalent, but it returns the same Internal Server Error error.

To add some more information, I used this to make the function calling the API :
https://community.monday.com/t/basic-c-api-v2-example/3419?

When using this query :

"{\"query\": \"{boards(limit:1){id name}}\"}"

Or this mutation :

"{\"query\":\"mutation{ create_item(board_id: XXXX, group_id: XXXX, item_name: XXXX){ id} }\"}"

It works just fine

Thank you all for the help :slight_smile:

Hey Will!

Escaping quotes basically means structuring your strings such that strings-inside-strings can be parsed accurately. It means putting a backslash \ escape character in front of inner quotes, to identify that those particular character should be parsed as a literal " and not the beginning or end of a string.

You’re doing that fine when making the queries that don’t use column values:
"{\"query\": \"{boards(limit:1){id name}}\"}".

However, when you use the column values argument, there are strings inside strings, which are themselves inside a string. We need to escape these twice.

Like this:

"{\"query\":\"mutation{ change_multiple_column_values(item_id:XXXX, board_id:XXXX, create_labels_if_missing: true, column_values: \\\"{\\\\\"status\\\\\" : {\\\\\"label\\\\\" : \\\\\"Done\\\\\"}}\\\"){ id} }\"}"

With this example, the full string is surrounded by the " character, the first level inner string is surrounded by \", the second level is surrounded by \\\" and the third level is surrounded by \\\\\".

If you use a JSON library in your code, you should be able to rely on a serializer to properly escape the inner quotes instead of having to worry about counting sets of five backslashes :slight_smile:

Let me know if the above explanation makes sense, and if the code works for you!

Cheers, Dipro :crystal_ball:

1 Like

Take a look here. This worked for me:

hi! I tried this one, but still I got internal server error.

Hey @candyOrate – can you open a new topic in the community about this? Please include a code snippet of the HTTP request you’re making, and the error response.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.