Creating a new item with column values populated (Python)

I am trying to create a python script that reads an XML file and imports the data to Monday.com Board.

I have the XML scraper built, now i need to learn the API side…
I have this example working without the 2 “Text” fields,
After i added the 2 text fields I get a ‘error_code’: ‘ColumnValueException’,
Can someone please help me understand why this error is happening? even chatGPT agree’s it should work but isnt…

MY CODE BELOW

Creating a new item with column values populated

apiKey = "apikey here"
apiUrl = "https://api.monday.com/v2"
headers = {"Authorization": apiKey}

query5 = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:3716595122, item_name:$myItemName, column_values:$columnVals) { id } }'
vars = {
    'myItemName': 'Item 1',
    'columnVals': json.dumps({
        'status': {'label': 'Working on it'},
        'date4': {'date': '2022-12-31'},
        'text': {'text': 'text here'},
        'text1': {'text': 'text here'}
    })
}
data = {'query': query5, 'variables': vars}
r = requests.post(url=apiUrl, json=data, headers=headers)

# make request
pprint(r.json())

MY ERROR BELOW
{‘error_code’: ‘ColumnValueException’,
‘error_data’: {‘column_type’: ‘TextColumn’, ‘column_value’: ‘{“text”=>“”}’},
‘error_message’: 'invalid value, please check our API documentation for the ’
'correct data structure for this column. ’
Guide to Changing Column Values’,
‘status_code’: 200}

Board Dump returns this

‘items’: [{‘column_values’: [{‘id’: ‘status’,
‘text’: ‘Working on it’,
‘title’: ‘Status’,
‘type’: ‘color’},
{‘id’: ‘date4’,
‘text’: ‘2022-12-31’,
‘title’: ‘Date’,
‘type’: ‘date’},
{‘id’: ‘text’,
‘text’: ‘’,
‘title’: ‘Text’,
‘type’: ‘text’},
{‘id’: ‘text1’,
‘text’: ‘’,
‘title’: ‘Text 1’,
‘type’: ‘text’}],
‘name’: ‘Item 1’},

UPDATE**
vars = {
‘myItemName’: ‘Item 1’,
‘columnVals’: json.dumps({
‘status’: {‘label’: ‘Working on it’},
‘date4’: {‘date’: ‘2022-12-31’},
‘text 1’: {‘text’: ‘2e11’}
})
}

Now will make a new item with No error… but the text in the “Text 1” field is blank on the new item…??

Hello @Tri and welcome to the community!

I hope you like it here :muscle:

You can pass a string as a value for a text column instead of an object.

Instead of:
‘text1’: {‘text’: ‘2e11’}

use:
'text1': '2e11'

Also, I see in the last message that there is a space between “text” and “1”. It should be “text1”.

I hope that helps!

Cheers,
Matias

1 Like

Thanks you for this…
I now having it working fine…
except it just adds items to the top group.
Is there a way to assign which group id like it to go into on the board?

query5 = ‘mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:3716595122, item_name:$myItemName, column_values:$columnVals) { id } }’
vars3716595122 = {
‘myItemName’: f’{self.md_fullname}‘, # Main Key Item, (We Use Customers Full Name)
‘columnVals’: json.dumps({
‘test’: f’{self.md_ro}‘, # ‘title’: ‘RO’,
‘text1’: f’{self.md_estimate}‘, # ‘title’: ‘Estimate #’,
‘text7’: f’{self.md_vin}', # ‘title’: ‘VIN’,
‘text0’: self.md_vehicle_model, # ‘title’: ‘Vehicle Model’,
‘text11’: self.md_total_hours, # ‘title’: ‘hours’,
‘numeric’: self.md_total_hours # ‘title’: ‘Total Hours’,
})
}

Hello again,

Yes! You can specify the group ID as explained in our documentation by adding the group_id parameter to the items resolver:

mutation {
    create_item (board_id: 1234567, group_id: "today", item_name: "new item") {
        id
    }
}

You can get the group IDs by using a query like this one:

{
  boards(ids: 1234567890) {
    groups {
      title
      id
    }
  }
}

Cheers,
Matias