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:

Is there a way to update columns of a new item together with the creation of the item? I know that after creating the item name you can then get the item id and mutate the rest of the columns, but is there a way to directly update the respective columns? Say when making a post request through a contact form with the name and email fields along with the name? name being item_name in this case

Hey @M65D85 – yes indeed! You can pass a JSON string of column values in the “column_values” parameter to update an items columns upon creation.

Check out this post for some examples in cURL: cURL Examples for API v2 :)

Cheers,
Dipro

1 Like

So may you please see if this is correct:

$token = ‘[ token ]’;

$url = ‘https://user.monday.com/v2/’;

$query=’ mutation { create_item (board_id: 341727670, item_name: “someone”, column_id: “{“first_name5”: "test text "}” ) { text } } ’ ; HOW DO I ADD MULTIPLE COLUMNS HERE? note the first_name is the id of the column does it go that way or is there another way to do this?

$headers = [‘Content-Type: application/json’, ‘User-Agent: [whatpresents] GraphQL Client’, ‘Authorization:’ . $token]; $data = @file_get_contents($url, false, stream_context_create([ ‘http’ => [ ‘method’ => ‘POST’, ‘header’ => $headers, ‘content’ => json_encode([‘query’ => $query]), ] ]));
$tempContents = json_decode($data, true);

And is this header section correct?

Thanks for your help! :slight_smile:

please your help is much needed!

This topic was automatically closed after 3 days. New replies are no longer allowed.