Skip to main content

Hello,


I am using Python to query monday API.

I have been spending many hours trying to use “change_column_value” on a link column, in vain.

I saw I wasn’t the only one to have this issue but I still couldn’t solve it.


This is my code:


def update_field(item_id: int, column_id: str, value):
value_str = json.dumps(value).replace('"', '\\\\"')
print(value_str)
query = f'''
mutation {{
change_simple_column_value(
board_id: {BOARD_ID},
item_id: {item_id},
column_id: "{column_id}",
value: "{value_str}"
) {{
id
}}
}}
'''
response = requests.post(url=MONDAY_URL, json={'query': query}, headers=monday_headers)

return response.json()

some_url = 'https://www.google.com'
some_text = 'Google'
print(update_field(item_id=item_id, column_id='link', value={'url': some_url, 'text': some_text}).json())

This code returns:


{\\"url\\": \\"https://www.google.com", \\"text\\": \\"Google\\"}
{'data': {'change_simple_column_value': {'id': '0000000000'}}, 'account_id': 00000000}

(I replaced the numbers by 0 for safety matters)


When I print json.dumps(value_str) I get {"url": "https://www.google.com", "text": "Google"}.


Returning back on my Monday board, I can see that the changes have been done, but not accurately. Here is what I get when I get the item:


{'id': 'link', 'title': 'Link column', 'value': '{"url":"https://%7B%22url%22:","text":"\\\\"https://www.google.com\\\\", \\\\"text\\\\": \\\\"Google\\\\"}","changed_at":"2023-05-12T10:14:02.242Z"}'}

I would be grateful if you could help me through this issue.


twan

hi @twan


So, from your example it shows that the value


'value': '{"url":"https://%7B%22url%22:","text":"\\\\"https://www.google.com\\\\", \\\\"text\\\\": \\\\"Google\\\\"}","changed_at":"2023-05-12T10:14:02.242Z"}'

you are sending to the column is picked up by monday and URL-encoded, hence is starts with %7B%22 (which unencoded is {"). I’m not a Python expert but it looks like json.dumps URL-encodes automatically and when printing it out it decodes it again.


Hi Bas de Bruin,


Thank you for your help.

I am not sure what changes to make your message suggest.

I wrote the value of value_str in a .txt file to see if I get the same output as when printing: yes.


I don’t see what’s wrong in the format of value_str since when I’m looking at it, it’s a string representing a json with 2 keys: “url” and “text”, as in the column.


Hello there @twan,


You can use something like this:


mutation {
change_multiple_column_values(
board_id: 1234567890
item_id: 1122334455
column_values: "{\\"link\\" : {\\"url\\" : \\"http://monday.com\\", \\"text\\":\\"go to monday!\\"}}"
) {
id
}
}

Which I translated to Python using Postman into:


import http.client
import json

conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\\"query\\":\\"mutation {\\\\n change_multiple_column_values(\\\\n board_id: 1234567890\\\\n item_id: 1122334455\\\\n column_values: \\\\\\"{\\\\\\\\\\\\\\"link\\\\\\\\\\\\\\" : {\\\\\\\\\\\\\\"url\\\\\\\\\\\\\\" : \\\\\\\\\\\\\\"http://monday.com\\\\\\\\\\\\\\", \\\\\\\\\\\\\\"text\\\\\\\\\\\\\\":\\\\\\\\\\\\\\"go to monday!\\\\\\\\\\\\\\"}}\\\\\\"\\\\n ) {\\\\n id\\\\n }\\\\n}\\",\\"variables\\":{}}"
headers = {
'Content-Type': 'application/json',
'Authorization': 'MYAPIKEY',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

I hope that helps!


Cheers,

Matias


Reply