Skip to main content

Dear Team ,

I’m making an application in Python to send data via Monday’s API.

I’ve read a lot of threads, but I still don’t understand how to do it.

Can we create items directly with values?
Example :
(Creating a new item with column values populated (Python) - #4 by Tri)

Other example :
(How to post to a form using Monday.com's API?)

Where you have to create the item, then update this item, as it says here:

I wanted to do it in this form:

{ change_column_values (board_id: ' + str(board_id) + ', item_id: '+ str(rjson["data"]["create_item"]["id"]) + ', column_values: $columnValues)

but I can not.

Can you help me ?

Hello there @Jefforion,

You can create items with populated columns via the API with a query like this one:

mutation {
  create_item(
    board_id: 1234567890
    group_id: "topics"
    item_name: "new item"
    column_values: "{\\"status\\":\\"Done\\", \\"text\\":\\"My Text\\"}"
  ) {
    id
  }
}

Here is the Postman example 😁

Cheers,
Matias


Hello @Matias.Monday ,

I tested with this, but it does not bring up the information in the columns.

Here are the different tests :

    # Postman exemple : "query": "mutation {create_item (board_id: 1234567890, group_id: \\"topics\\", item_name: \\"new item\\", column_values: \\"{\\\\\\"status\\\\\\":\\\\\\"Done\\\\\\", \\\\\\"text\\\\\\":\\\\\\"My Text\\\\\\"}\\") {id}}" 
    print("Try 1")
    try:
        query = 'mutation { \\
                    create_item( \\
                    board_id: 6373870433 \\
                    item_name: "Foo 1" \\
                    column_values: "{\\\\\\"num\\\\\\":\\\\\\"123\\\\\\", \\\\\\"text\\\\\\":\\\\\\"Bar\\\\\\"}"\\
                    ) \\
                { id } }'
        data = {'query': query}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        rjson = r.json()
        print(rjson)
    except Exception as e:
        print("NOK -- The query is wrong...")
        print(e)
        exit()

    print("Try 2") 
    try:
        query = 'mutation { \\
                    create_item( \\
                    board_id: 6373870433 \\
                    item_name: "Foo 2" \\
                    column_values: "{\\"num\\":\\"123\\", \\"text\\":\\"Bar\\"}"\\
                    ) \\
                { id } }'
        data = {'query': query}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        rjson = r.json()
        print(rjson)
    except Exception as e:
        print("NOK -- The query is wrong...")
        print(e)
        exit()

    print("Try 3")
    try:
        var =  json.dumps({
                    "num":"123",
                     "text":"Bar"
                    })
        
        query = 'mutation { \\
                    create_item( \\
                    board_id: 6373870433 \\
                    item_name: "Foo 3" \\
                    column_values: ' \\
                    + str(var) \\
                    + ' ) { id } }'
        data = {'query': query}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        rjson = r.json()
        print(rjson)
    except Exception as e:
        print("NOK -- The query is wrong...")
        print(e)
        exit()

    print("Try 4")
    try:
        var =  '{\\"num\\":\\"123\\",\\"text\\":\\"Bar\\"})'
        print(var)
        query = 'mutation { \\
                    create_item( \\
                    board_id: 6373870433 \\
                    item_name: "Foo 4" \\
                    column_values: ' \\
                    + str(var) \\
                    + ' ) { id } }'
        data = {'query': query}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        rjson = r.json()
        print(rjson)
    except Exception as e:
        print("NOK -- The query is wrong...")
        print(e)
        exit()

Here are the answers :


Try 1
{'data': {'create_item': {'id': '6374309917'}}, 'account_id': 6007217}
Try 2
{'errors': [{'message': 'Parse error on ":" (STRING) at [1, 166]', 'locations': [{'line': 1, 'column': 166}]}], 'account_id': 6007217}
Try 3
{'errors': [{'message': 'Parse error on "num" (STRING) at [1, 161]', 'locations': [{'line': 1, 'column': 161}]}], 'account_id': 6007217}
Try 4
{"num":"123","text":"Bar"})
{'errors': [{'message': 'Parse error on "num" (STRING) at [1, 161]', 'locations': [{'line': 1, 'column': 161}]}], 'account_id': 6007217}

For TRY 1, there is still the item to create, but not the columns.


It’s working !

    try:
        query = 'mutation { \\
                    create_item( \\
                    board_id: 6373870433, \\
                    item_name: "Foo 1", \\
                    column_values: "{\\\\\\"chiffres\\\\\\":\\\\\\"123\\\\\\", \\\\\\"texte\\\\\\":\\\\\\"Bar\\\\\\"}"\\
                    ) \\
                { id } }'
        data = {'query': query}
        r = requests.post(url=apiUrl, json=data, headers=headers)
        rjson = r.json()
        print(rjson)
    except Exception as e:
        print("NOK -- The query is wrong...")
        print(e)
        exit()

Juste copy this name (ID) :
image

In reality, the documentation is in English, but my Monday is French.
We should put a warning to indicate that this may vary depending on the country language in the documentation.


Hello @Jefforion,

I am glad you found the source of the issue 😁