But it seems something in my escaping of the string is not right and I get bad request!
I am begging for some help! I have been struggling with that for two days.
if someone has c# code to help me I will be so grateful.
Have you successfully made any API requests via your C# code? Can you show an example of this, as well as the exact methods you’re using to make this request?
Yes I have used the helper class - even I wasted time to make my own client service and some modifications @grt-s class but no matter if i use his helper class or my service - the result is the same.
of course I have made some queries that were successful - 1. his query 2. I successfully get all the items and column values of my board.
or modify columns data 0- cannot do anything. It just gives me bad request and the problem is that i don’t get any information further to see where is my mistake. My company wants to work with monday - but I should find a way to populate with data.
Thank you so much in advance I have wasted two days already on this
Hey Tanya! Thanks for sending that context over. Glad you’ve gotten a create_item mutation to work. We can focus on the column values part now
First off, let me start by saying I’m not a C# expert. But I do know our API inside out so I’m sure we can put our heads together to solve this!
Our API takes column values as string-ified JSON, which sometimes includes strings inside it.
If we try to explicitly pass these strings-inside-strings, you will sometimes run into issues with bad requests. It’s beneficial to instead let a JSON library do the hard work I’ve heard Json.NET is a good one to use.
I would also recommend using GraphQL variables to pass your arguments. This way, you don’t have to escape anything and instead you can pass your arguments as part of a JSON object.
Here’s a programming pattern that I’ve found helpful when making requests like this work in an environment that does not play nicely. It’s kind of a mix of psuedocode and C#, I’ll let you edit it to work in your environment
// store query as a string, declaring the item name and column values as GraphQL variables
string myQuery = "mutation ($name: String!, $values: JSON!) {create_item(board_id: 454686247, item_name: $name, column_values:$values) { id} }"
// store column values as a dictionary
string vals = @{"text" : "This is a text value!"}
// convert column values into JSON string
string vals_json = JSON.SerializeObject(vals)
// create variables dictionary using the item name
string myVariables = @{"name" : "Item name", "values" : vals_json}
// construct payload for actual API request
string query = @{""query"" : myQuery, ""variables"" : myVariables}
What do you think? Does that make sense? Let me know
Hey @taniamm2002 I replied to your issue on my C# demo on GitHub but thought I’d post here too in case anyone else walks down this path! Here’s a link to the issue.
This is pretty ugly code I know with all of the string escaping! If you need to scale it up for several different mutations it is probably much easier to use a JSON library, use GraphQL variables, and build up the query as @dipro suggests. If I get some time at some point I’ll have a go at a nicer version and add it to the example repo.
All that said the current one seems to work for me so it might get you unstuck for now
Thank you thank you so much I tried to follow the upper pattern and I have achieved creating an element. Again problem with the column values. but I am sure I will have a result.
For the column values, you sometimes need to serialize the column data as JSON before putting them in the variables object, but in other situations the data gets passed fine without this step. For example, in my Python code I need to do double-serializing, but JS handles it with no issue.
If you keep having issues with item creation, you can also simplify this call by first creating the item and then looping through the columns and updating them one at a time. @lucy.parry’s amazing example walks through this