Skip to main content

Create item with numeric column value in Python

  • August 3, 2021
  • 4 replies
  • 1530 views

Hey there, I’m having some trouble creating an item with a numeric column value. No matter what formatting I try, I get an error that says I am using an incorrect data structure for that column. Code and error response is below. Any tips appreciated!

query6 = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:BOARD_ID_HERE, item_name:$myItemName, column_values:$columnVals) { id } }'
vars = {
	'myItemName' : 'Hello everyone!',
	'columnVals' : json.dumps({
		'numbers1' : {'value' : '25'}

	})
}
data = {'query' : query6, 'variables' : vars}

r = requests.post(url=apiUrl, json=data, headers=headers)

numbers1 is the ID of the column in question. I’ve also tried the following formats in place of that line:

'numbers1' : {'value' : "25"}
'numbers1' : {'value' : 25}
'numbers1' : {'value' : "\\"25\\""}

Every time I get the same error:

{'error_code': 'ColumnValueException', 'status_code': 200, 'error_message': 'invalid value, please check our API documentation for the correct data structure for this column. https://monday.com/developers/v2#column-values-section', 'error_data': {'column_value': '{"value"=>"25"}', 'column_type': 'NumericColumn'}}

I’ve checked the documentation and can’t find any examples in Python of a numeric value being supplied for the create_item action. Any help appreciated on how to format numeric values in the request variables!

This topic has been closed for replies.

4 replies

  • Participating Frequently
  • August 4, 2021

Just the value would work
‘columnVals’: json.dumps({
“numbers1”: “42”
})


Forum|alt.badge.img
  • monday.com Team Member
  • August 4, 2021

Hi @alex_abrahams,

I agree with @Shilpa, if the only column values you’re looking to populate are numbers columns, you can absolutely just send the number directly, without the value portion.

Try this out and let us know if you continue to experience errors.


andrew.shatz
  • Participating Frequently
  • August 4, 2021

Hello @alex_abrahams,

Have you looked at the moncli package perchance? You can easily accomplish this using the following code below.

from moncli import client

client.api_key = "YOUR_API_KEY"
item = client.get_items(ids=[your_item_id])[0]
number_value = item.get_column_values["TITLE_OR_ID_OF_YOUR_NUMERIC_COLUMN"]
number_value.number = your_number
update_item = item.change_column_value(number_value)

If you are at all interested, please feel free to download the package using the following command.

$ pip3 install moncli

Please feel free to reach out if you have any questions.

All the best and happy coding,

Andrew


  • August 11, 2021

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.