'change_simple_column_value' mutation on a status column

Hello,

I’ve been struggling to change the value of some columns of an item.
I am using Python to request the API.

These are the 2 columns I want to change:
{'id': 'status_1', 'title': 'Etape', 'value': '{"index":5,"invalid":false,"changed_at":"2023-06-06T08:07:50.170Z"}'}
{'id': 'multi_select', 'title': 'Types', 'value': '{"ids":[2,1,4],"changed_at":"2023-06-06T07:28:20.062Z"}'}

I couldn’t find in the API documentation the needed format for these types of column. For simple text, it’s pretty easy. For these types of column, I encounter some difficulties.
This is my code:

query = '''
    mutation {
        change_simple_column_value(
            board_id: %s,
            item_id: %s,
            column_id: "%s",
            value: "%s"
        ) {
            id
        }
    }
    ''' % (0123456789, 987654321, 'status_1', '{"label": "Some label"}')
    response = requests.post(url=MONDAY_URL, json={'query': query}, headers=monday_headers)

Note that I also tried putting {"id": "1"} into the value to change the status from the id and not from the label.

For the ‘multi_select’ column, I used the same code but with '{"ids":%s}' % json.dumps([1]) for the value.

None of these work. I get the following errors:

  • For ‘status_1’ column:
    'errors': [{'message': 'Parse error on ": " (STRING) at [7, 28]'
  • For ‘multi_select’ column:
    'errors': [{'message': 'Parse error on ":[1]}" (STRING) at [7, 26]'

I know the problem is the value, but I couldn’t find what I am doing wrong.

I’d be grateful for your help.
Antoine

Hello there @twan,

I have created an example for you. I will share the mutation itself and I will share how Postman exports it to Python:

The mutation:

mutation {
  change_multiple_column_values(
    item_id: 1234567890
    board_id: 1122334455
    column_values: "{\"status\" : {\"label\" : \"Done\"}, \"dropdown\": \"My label\" }"
  ) {
    id
  }
}

Python http.client:

import http.client

import json

conn = http.client.HTTPSConnection("api.monday.com")

payload = "{\"query\":\"mutation {change_multiple_column_values( item_id: 1234567890, board_id: 1122334455 column_values: \\\"{\\\\\\\"status\\\\\\\" : {\\\\\\\"label\\\\\\\" : \\\\\\\"Done\\\\\\\"}, \\\\\\\"dropdown\\\\\\\": \\\\\\\"My label\\\\\\\" }\\\") { id}}\",\"variables\":{}}"

headers = {

'Authorization': 'APITOKENHERE',

'Content-Type': 'application/json',

}

conn.request("POST", "/v2", payload, headers)

res = conn.getresponse()

data = res.read()

print(data.decode("utf-8"))

Python - Requests:

import requests
import json

url = "https://api.monday.com/v2"

payload="{\"query\":\"mutation {change_multiple_column_values( item_id: 1234567890, board_id: 1122334455 column_values: \\\"{\\\\\\\"status\\\\\\\" : {\\\\\\\"label\\\\\\\" : \\\\\\\"Done\\\\\\\"}, \\\\\\\"dropdown\\\\\\\": \\\\\\\"My label\\\\\\\" }\\\") { id}}\",\"variables\":{}}"
headers = {
  'Authorization': 'APITOKENHERE',
  'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Let me know if this helped!

Cheers,
Matias

Hello Matias,

Thank you for your help.
I tried your code but with change_simple_column mutation.

Here is the query once printed:

    mutation {
        change_column_value(
            board_id: 0000000000,
            item_id: 000000000,
            column_id: "status_1",
            value: {\\\"label\\\" : \\\"Done\\\"}
        ) {
            id
        }
    }

I’ve put the same thing as you in the ‘value’ field of the mutation:

value: {\\\\\\\"label\\\\\\\" : \\\\\\\"Done\\\\\\\"}

Unfortunately I still encounter a parsing error:

'message': 'Parse error on "\\\\" (error) at [7, 21]'

I’ve tried many other things, adding slight differences, in vain…

Thank you in advance for your help,
Antoine

Hello there,

I found one of my mistake. I were using ‘change_simple_column_value’ instead of ‘change_column_value’. This makes a huge difference since the first one can only deal with simple data types (such as texts and numbers).

Moreover, I found the needed format for the ‘value’ field of the query.
The value requires the object to be between double quotes. For the keys and values (here “label” and “Done”), the string must contain the backslash and the quotes. So you need to escape the backslash.
Here is an example of value taken by the query:

"{\"label\" : \"Done\"}"

This also works with the index:

"{\"index\" : 2}"

You can get those in Python with:

"%s" % '{\\"label"\\" : \\"Done\\"}'

or

"\"{\\\"label\\\" : \\\"Done\\\"}\""

You can also use json.dumps() on a dictionary to get a json string. Use it two times in a row to escape the entire string, thus getting the right format. Here is an example:

json.dumps(json.dumps({"label": "Done"}))

This is helpful when using ‘change_multiple_column_values’ mutation.

I hope this will help the amateurs like me who encounter the same difficulties :slight_smile:

To conclude, the title of my question shows the main issue: you can’t use ‘change_simple_column_value’ on a status column.
The rest is just a matter of formatting with Python.

Antoine

Hello again @twan,

Thank you for sharing your solution here!

I am sure it will help others :grin:

Cheers,
Matias