query = f"“”
mutation {{
change_column_value (board_id: {board_id}, item_id: {item_id}, column_id: {column_id}, value: “{client_name}”) {{
id
}}
}}
“”"
response = requests.post(
“https://api.monday.com/v2/”, json={“query”: query}, headers=HEADERS
)
if response.status_code == 200:
print(
f"API Response (Status Code: {response.status_code}):\n{response.json()}"
) # Print the API response for debugging
data = response.json()
print(
f"Update response for item {item_id} on board {board_id}: {data}"
) # Print the update response for debugging
else:
print("Bad Request: ", response.status_code)
this giving me 500 status code
Hello there @Sagar and welcome to the community!
I hope you like it here
It looks like you might be trying to pass data from variables, but the values of the variables are not there. I created a working example in Postman and exported it to Python for you:
import http.client
import json
conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\"query\":\"mutation myMutation($boardId: ID!, $itemId: ID!, $columnId: String!, $clientName: String!) {\\nchange_simple_column_value (board_id: $boardId, item_id: $itemId, column_id: $columnId, value: $clientName) {\\nid\\n}\\n}\",\"variables\":{\"boardId\":1234567890,\"itemId\":1122334455,\"columnId\":\"text\",\"clientName\":\"Some name\"}}"
headers = {
'Authorization': 'MYAPITOKENHERE',
'API-version': '2023-10',
'Content-Type': 'application/json',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
I hope that helps!
Cheers,
Matias
Thank you Matias,
Can you please help me to retrieve all the items present in the board using graphql query using board_id that i provide.
Hello again,
You can use a query like this one:
import http.client
import json
conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\"query\":\"query myQuery($boardId: [ID!]) {\\n boards(ids: $boardId) {\\n items_page(limit: 30) {\\n cursor\\n items {\\n name\\n id\\n }\\n }\\n }\\n}\",\"variables\":{\"boardId\":1234567890}}"
headers = {
'Authorization': 'APITOKENHERE',
'API-version': '2023-10',
'Content-Type': 'application/json',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Then you use the cursor as explained here:
import http.client
import json
conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\"query\":\"query myQuery($boardId: [ID!]) {\\n boards(ids: $boardId) {\\n items_page(limit: 30, cursor: \\\"MSw1MTg1Mjk2MTQ5LFl1OWlhS0dBVWZrNGd1V0hiVVdRTiwxMSw1LHwyODc4MTA0NTU0\\\") {\\n cursor\\n items {\\n name\\n id\\n }\\n }\\n }\\n}\",\"variables\":{\"boardId\":1234567890}}"
headers = {
'Authorization': 'APITOKENHERE',
'API-version': '2023-10',
'Content-Type': 'application/json',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
And you go through the pages, passing always the next cursor until there is no cursor in the response, as explained in the documentation sent before.
I hope that helps!
Cheers,
Matias
Thank you a lot matias.
Can you please Provide me guide on how can I put the code in monday.com so that my friend can trigger the code when any events occurs. Please guide me on this,
Hello again @Sagar,
In this case, the script should be in an server of your choice. And you can use webhooks as explained here to notify your server when an event occurs in monday.com so that you can then run that script.
You can also do this without endpoints if the event you want to listen to happens outside of monday. You can use a custom app with a custom trigger.
I suggest checking the documentation in these links to see how this works.
Please let me know if you have any questions about the documentation!
Cheers,
Matias