Internal Server Error when changing/creating column values

Hi.
I am trying to update a column value using the following query:

mutation {change_column_value (board_id: #######, item_id: #######, column_id: \"text\", value: \"hello\") {name}}

And creating a new item with given values using the following query:

mutation {create_item (board_id: ########, item_name: \"New Item\", column_values: \"{\\\'text\\\': \\\'hello\\\'}\") {id}}

However I get Internal Server Error (500).
What is the problem with these queries?

Note:

  1. A column with the id ‘text’ does exist in the board
  2. I have no problem creating an item with empty column_values (just {}), nor any problem in reading board contents.
  3. The stringified JSON (the arg of column_values) is generated automatically by str(dict).

Thanks!

Hey Michael!

Can you share the code you’re using to make the query? I’d love to know exactly the data you’re sending to our server so we can troubleshoot.

Cheers,
Dipro

I implement the API request in Python. Please see the attached code.

MONDAY_TOKEN = 'XXXXXXXXXXXX'

input_dict = {"text": "Hello"}
empty_dict = {}

query = "mutation {create_item (board_id: 284526560, item_name: \"New Item\",
column_values: \"%s\") {id}}" % str(input_dict)
payload = json.dumps({"query": query})

r = requests.post("https://api.monday.com/v2/",
                  headers={'Content-Type': 'application/json',
                           'Authorization': MONDAY_TOKEN},
                  data=payload)

Where if I use str(input_dict) I get the 500 Internal Sever Error, and if I use str(empty_dict) the item is added successfully. The id of the text column is ‘text’. Using ‘Text’ (its label) as key does not change the outcomes.

Thanks!

Hey Michael!

Ah, I see the issue. When you pass input_dict as a string, it doesn’t escape the inner quotes, resulting in a malformed query string.

Instead of trying to manipulate your query string to include column values, I’d suggest passing them as variables.

Try something like this:

req_data = {"query" : "mutation($name: String!, $columns: JSON!)\
    				{create_item(item_name:$name, board_id:xxxx, column_values:$columns) \
    				{name id column_values {id value}}}",
                    # send columns as a variable to prevent string manipulation
    		"variables" : {"name" : name, "columns" : json.dumps(column_data)}} 
r = requests.post(url=monday_url, json=req_data, headers=headers)

Let me know if that works for you! :sunny: