Python API integration help

Hi, I have been struggling with this API, it could just be me but I don’t find the docs very useful.

I find the use of $ in variables names (within the examples) odd (in python context) and am not sure if they have any significance, I removed them and got different errors so I’m guessing they have.

I am attempting to get particular dashboard columns updated. This was the attempt (I cant see anything to mark text as code so apologies if this isn’t formatted as expected.

import requests
import json

apiKey = “value”
apiUrl = “https://api.monday.com/v2
headers = {“Authorization” : apiKey}

query5 = ‘mutation ($myItemName: String!, columnVals: JSON!) { create_item (board_id:BOARDID, item_name:$myItemName, column_values:$columnVals) { id } }’
vars = {
‘$myItemName’ : ‘Test’,
‘$columnVals’ : json.dumps({
‘text0’: ‘Title’,
‘text’: ‘Company’,
‘status’: ‘Customer’,
‘status5’: ‘High’,
‘phone’: ‘01234567890’,
‘email’: ‘Test@mail.com’,
‘date’: {‘date’ : ‘2020-08-27’},
‘text4’: ‘Lots of notes’
})
}

data = {‘query’ : query5, ‘variables’ : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
print(r.json())

This of course doesn’t work, the error being

{‘errors’: [{‘message’: ‘Parse error on “columnVals” (IDENTIFIER) at [1, 33]’, ‘locations’: [{‘line’: 1, ‘column’: 33}]}], ‘account_id’: REMOVED}

I have used their python examples and in general the API docs and it works. The below snippet is from a code that I have tested. You can replace the board id ‘1111111’ with yours and other column ids.

Within the vars section, we do not need the “$”

query5 = ‘mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:1111111, item_name:$myItemName, column_values:$columnVals) { id } }’
vars = {
‘myItemName’ : ‘ABC’,
‘columnVals’ : json.dumps({
‘status’ : {‘label’ : ‘Done’},
‘date4’ : {‘date’ : ‘1993-08-27’},
‘email’ : {‘email’: ‘itsmyemail@mailserver.com’, ‘text’: ‘itsmyemail@mailserver.com’}
})
}

data = {‘query’ : query5, ‘variables’ : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
jsondata = r.json()
print(jsondata)

Aarr thank you for the response Shilpa, I was, of course, passing in strings as a value to the key. Looking at your example they are clearly dictionaries of various key:value pairs. Is there a reference to these anywhere? So I can see what each key type is expecting?

Each ‘key’ is the column id. You can find out the type it is from the columns on your board

This seems to have the info I wanted. Thanks

Hey @meandI - apologies for the delay here. Shoutout to to rockstar @Shilpa for stepping in.

Let me know if we can help with anything else!

-Daniel

‘status’ : {‘label’ : ‘Done’},

How do you know what goes in that middle field? Status is of type “color”. Why is this “label” in this instance?

And for the life of me I can’t figure out a “numeric” field. I’ve tried “label”, “numeric”, “text”… and with quotes on the number value or without. No combination of values seems to work.

Frankly… this API is really terribly documented…

The doumentation has examples for each column “type”

For status - https://monday.com/developers/v2#column-values-section-status
For numeric - https://monday.com/developers/v2#column-values-section-number

For a numeric example, if the column id is “numbers” and value is 3 you would have to format as below.
‘columnVals’ : json.dumps({
‘status’ : {‘label’ : ‘Done’},
‘date4’ : {‘date’ : ‘1993-08-27’}
‘numbers’: “3”
})

They have complete examples in https://support.monday.com/hc/en-us/articles/360013483119-API-Quickstart-Tutorial-Python

Hey @Shilpa - thanks so much for providing awesome answers here throughout the thread, I really appreciate it! So helpful :slight_smile:

@jrainesHMRI I am sorry to hear you feel that way about our API docs, and I’d love to see if @Shilpa 's suggestions were able to provide a helpful pointer in this case. Would you be able to review and let us know if that helps?

To shed more light on this, the Status column uses both labels and index as value keys. Labels allow you to use plain text to populate the data, like using “Done” to set the Status column to a Green Status label, while Indexes would be based on Color. You can find the colors by index deck here:

https://view.monday.com/471878000-13f8e67ced7f0463687b9694f8044fac

For values to the Numbers column, you do need to send an Int as the value.

-Alex

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