I am trying to use a variable in the API to query a board using Python.
I want to use the variable to replace the board id.
I can successfully do a mutation using a variable for the board id, but I can’t get the query right.
This one works:
import requests
import json
apiKey = “**********************************************************”
apiUrl = “https://api.monday.com/v2”
headers = {“Authorization” : apiKey}
query = ‘{boards (ids: 590638178) { name id description items { name column_values{title id type text } } } }’
data = {‘query’ : query}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
print(r.json())
Data returned:
{‘data’: {‘boards’: [{‘name’: ‘M1-Weekly Schedule’, ‘id’: ‘**********’, ‘description’: ‘Board Owner: *******. Only **** can change data in Monday (dates etc). \nView & Comment Access: All Management & Supervisors. \n\nFunction: MYOB Exo - Monday.com will only collect any new jobs “Pending Commencement” in MYOB Exo and place them in the “New Jobs” group. \n\nPhase 2 - Man Hours / Labour / Equipment Type’, ‘items’:…
This doesn’t work:
import requests
import json
apiKey = “**********************************************************”
apiUrl = “https://api.monday.com/v2”
headers = {“Authorization” : apiKey}
board_id = 590638178
query = ‘($myBoardID: Int!) {boards (ids: $myBoardID) { name id description items { name column_values{title id type text } } } }’
vars = {‘myBoardID’ : board_id}
data = {‘query’ : query, ‘variables’ : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
print(r.json())
No data is returned:
{‘errors’: [{‘message’: ‘Parse error on “(” (LPAREN) at [1, 1]’, ‘locations’: [{‘line’: 1, ‘column’: 1}]}], ‘account_id’:…
However, I can successfully use a variable for board ID in a mutation e.g.
query = 'mutation ($myItemName: String!, $myBoardID: Int!, $columnVals: JSON!) { create_item (board_id:$myBoardID, …