Change_simple_column_value mutation returning a 500 error


I am trying to update a column on my board - it is a number. I am using the change_column_value endpoint in the API and Python.

Here is my code:

def updateColValue(self, boardId, itemId, colId, value, mondayToken): 

		dictHeader = {'Content-Type': 'application/json', "Authorization":self.mondayToken}
		mondayURL = ""


			mutation = f"{{ change_column_value(board_id: int(boardId), item_id: int(itemId), column_id: colId, value: value) {{ id }} }}"
			payload = f"{{\"query\":\"mutation: {mutation}}}"
			response = requests.request("POST", mondayURL, headers=dictHeader, data=payload)

		except Exception as e: 
			print (f"{cm.WARNING}There was an error running a column update:\nColumn: {colId}\n{e}")

I keep getting a 500 error returned. I suspect it is because my query formatting is not correct. Would appreciate any help. I was using this Q&A as a guide:

I am unsure how yours variables are being substituted into your query. There are no GraphQL variables defined in it, nor are you providing the variables in your payload.

f strings are your enemy not your friend for this task, even though you’ve probably seen them all over for GraphQL examples. Trying to ensure quotes are escaped correctly, etc. is a nightmare you don’t have to endure.

GraphQL queries are strings, you can define variables in them (not to be substituted as part of an f-string, but by the API server itself!), then pass variables as a separate object in your request.

GraphQL requests are JSON of objects that have two keys, query and variables. query is your query string (the mutation in this case, with the word mutation at the start, basically just copied right out of the playground as a string)

variables is an object with a key for each variable name used in the query string, and the value is the value for the variable - it needs to be the correct type. The documentation lists the types of arguments. JSON type means its an object that has been serialized to a JSON string using json.dumps.

You then serialize the request object to json and send it.

Here is a longer thread that may also provide some light.

Below is a link directly to the variables section.

1 Like