Create_item function with column_values not working

Hi,

I want to create a new item with column values already applied to it, but there is no proper example all around the internet to get information from.
I have this code:

query3 = 'mutation { create_item (board_id:1917614834, group_id: topics, item_name: Teszt2, column_values: "{\"status\":{\"label\":\"Medium\"}}}' data = {'query': query3} r = requests.post(url=apiUrl, json=data, headers=headers) # make request print(r.json())

But it says:
{'errors': [{'message': 'Parse error on ":{" (STRING) at [1, 111]', 'locations': [{'line': 1, 'column': 111}]}], 'account_id': 10454884}

I don’t know how to write the query line after column_values.
Can you please help me with the correct code line for the query?
I always get a Parse error, no matter what type of column I want to update.

Hello @ChrisNemes,

group_id and item_name are supposed to be a strings
Try this:

mutation { create_item (board_id:1913125449, item_name: "Teszt2", group_id: "topics",create_labels_if_missing: true, column_values:"{\"status\":{\"label\":\"Medium\"}}") {
  id
}}

Tried your solution, and I got the same error:
query3 = 'mutation { create_item (board_id:1913125449, item_name: "Teszt2", group_id: "topics",create_labels_if_missing: true, column_values:"{\"status\":{\"label\":\"Medium\"}}") { id}}'

Result:
{'errors': [{'message': 'Parse error on ":{" (STRING) at [1, 138]', 'locations': [{'line': 1, 'column': 138}]}], 'account_id': 10454884}

I’m using the API in python, if it counts.

Sorry, I’m not conversant in Python but the solution I provided works. I’ve tested it in the playground.

1 Like

Thank you for your efforts! :slight_smile:

1 Like

Finally I managed to make one function that works:

createItemWithData(board_id, vars, groupID)

It uses 3 variables:

  • the board_id comes from the board where the item will be created
  • the vars stores all the variables/attributes/column values the item has
  • groupID is used for grouping items in boards

vars looks like this:

vars = {
  'myItemName': "MyItem",
  'columnVals': json.dumps({
  'username': "Chris",
  'task': "That is my job",
  'starttime': {"hour": int(01), "minute": int(13)},
  'endtime': {"hour": int(03), "minute": int(35)},
  })
}

The column ID-s are username, task, starttime and endtime.

and the function:

def createItemWithDataJob(board_id, vars, groupID):
    '''Creating items with column values'''

try:
    query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:' + str(board_id) + ', group_id: ' + str(groupID) + ', item_name:$myItemName, column_values:$columnVals) { id } }'
    data = {'query': query, 'variables': vars}
    r = requests.post(url=apiUrl, json=data, headers=headers)  # make request
    print(r.json())
except Exception as e:
    print("Something is wrong...")
    print(e)
    exit()

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