Doing some more testing the issue seems to be within how python formats quotes when passing this data
output = '{"query":"mutation{change_multiple_column_values(item_id:$myItemID, board_id:$myBoardID, column_values:\\"{\\\\\\"link9\\\\\\" : {\\\\\\"url\\\\\\" : \\\\\\"https://acep-space.monday.com/boards/$myBoardID/pulses/$myItemID\\\\\\", \\\\\\"text\\\\\\" : \\\\\\"Sandbox Task 13\\\\\\"}}\\"){id}}"}'
test = output
print(test)
query = '"mutation{change_multiple_column_values(item_id:$myItemID, board_id:$myBoardID, column_values:\\"{\\\\\\"link9\\\\\\" : {\\\\\\"url\\\\\\" : \\\\\\"https://acep-space.monday.com/boards/$myBoardID/pulses/$myItemID\\\\\\", \\\\\\"text\\\\\\" : \\\\\\"Sandbox Task 13\\\\\\"}}\\"){id}}"'
test = query
print(test)
query = "mutation{change_multiple_column_values(item_id:$myItemID, board_id:$myBoardID, column_values:\\"{\\\\\\"link9\\\\\\" : {\\\\\\"url\\\\\\" : \\\\\\"https://acep-space.monday.com/boards/$myBoardID/pulses/$myItemID\\\\\\", \\\\\\"text\\\\\\" : \\\\\\"Sandbox Task 13\\\\\\"}}\\"){id}}"
data = {"query": query}
test = (data)
print(test)
The top format is what is expected by Monday, the middle format was used to test various implementations of passing the query, the final format is what I’m using so that I can also pass variables into the final request in this the escape characters are formatted incorrectly.
                
     
                                    
            Hi @NeelPi!
It looks like you have more slashes than necessary. The column values should be formatted like this, for example:
column_values: "{\\"status\\": \\"Done\\"}"
                
     
                                    
            Specifically with the link column type what would be the best way pass variables into the post request?
                
     
                                    
            I have tried multiple ways of providing column values and the json parser in python seems to not be able to understand what is being sent.
                
     
                                    
            I ask because this is what the API is looking for
query: mutation {change_multiple_column_values(item_id: 2973227073, board_id: 2973227049, column_values: "{\\"link\\" : {\\"url\\" : \\"\\", \\"text\\" : \\"\\"}}") { id} }
however I want to use mutations since the values for columnID, url, and text are variable and determined by my code from other queries so my final query would look something like
query: mutation ($boardID:Int!,$itemID:Int!,$colID:String!,$itemURL:String!,$itemName:String!,$linkVal: JSON!) {change_multiple_column_values(item_id:[$itemID], board_id:[$boardID],column_values:[$linkVal]){id}}, variables: {'boardID': boardID, 'itemID': itemID, 'colID': colID, 'itemURL': itemURL, 'itemName': itemName, 'linkVal': "{ [$colID] : {"url" : [$itemURL], "text": [$itemName]}}"}
or
query: mutation ($boardID:Int!,$itemID:Int!,$colID:String!,$itemURL:String!,$itemName:String!) {change_multiple_column_values(item_id:[$itemID], board_id:[$boardID],column_values:"{[$colID] : {\\"url\\" : [$itemURL], \\"text\\" : [itemName]}}"){id}}, variables: {'boardID': boardID, 'itemID': itemID, 'colID': colID, 'itemURL': itemURL, 'itemName': itemName}
However with either solution I am unable to understand where to place the escape characters so that the json parser understands and I get to use my variables as inputs.
                
     
                                    
            Solution: I ended up having to remove the square brackets around my variables in the mutation and passed the value for linkVal through JSON.dumps.
For anyone curious this was how the POST request query had to be set up:
    vars = {
        'boardID':boardID,
        'itemID':itemID,
        'linkVal': json.dumps({
            colID: {'url': itemURL, 'text': itemName}
        })
    }
And this is the full code:
import requests
import json
apiKey = "myAPIKey” 
piUrl = https://api.monday.com/v2
headers = {"Authorization": apiKey}
boardID = myBoardID
query = 'query ($boardID:Int!) {boards(ids:[$boardID]){items{id name}}}'
vars={
    'boardID': boardID
}
data = {'query': query, 'variables': vars}
r = requests.post(url=apiUrl, json=data, headers=headers)  # make request
itemsInjest=r.json()
itemsVal=itemsInjest['data']['boards']
boardID=str(boardID)
itemsURL=sum(([
    [
        int(itemsIDs['id']),
        itemsIDs['name'],
        f'https://acep-space.monday.com/boards/{boardID}/pulses/{itemsIDs["id"]}'
    ]
    for itemsIDs in items['items']] for items in itemsVal),[])
boardID = int(boardID)
query = 'query ($boardID:Int!) {boards(ids:[$boardID]){items(limit:1){column_values{id title type}}}}'
vars = {
    'boardID': boardID
}
data = {'query': query, 'variables': vars}
r = requests.post(url=apiUrl, json=data, headers=headers)  # make request
colInjest = r.json()
colData=colInjest['data']['boards'][0]['items'][0]['column_values']
colID = [colVal['id'] for colVal in colData if colVal['type'] == 'link' and colVal['title'] == 'Email Link'][0]
for itemID,itemName,itemURL in itemsURL:
    query = 'mutation ($boardID:Int!,$itemID:Int!,$linkVal: JSON!) { change_multiple_column_values(item_id: $itemID, board_id: $boardID, column_values: $linkVal){id}}'
    vars = {
        'boardID':boardID,
        'itemID':itemID,
        'linkVal': json.dumps({
            colID: {'url': itemURL, 'text': itemName}
        })
    }
    data = {'query': query, 'variables': vars}
    r = requests.post(url=apiUrl, json=data, headers=headers)  # make request
                
     
                                    
            This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.