Skip to main content

I am currently importing data into two boards to simulate a parent/child relationship. The two boards share a value companyName that will link them. I final part of the code I am pasting now works. However, I want to replace one of the hardcoded IDs with a variable. I’ve tried a number of ways without any success.


Query 1, not shown retrieves a JSON with the item ID, item name (company) from the parent board


Query 2, not shown retrieves a JSON with item ID, item name, company name from the child board


The loop below takes a single item from Q2, calls a function to find the matching company from Q1, then calls API to connect_boards.


for allItems2 in itemLevelData2:

singleItem2 = allItems2s‘items’]

# Loop for individual item detail

for itemDetail2 in singleItem2:

#Retrieve the entry ID

itemID2 = int(itemDetail2e‘id’])

columnValues = itemDetail2t‘column_values’]

#print(columnValues)

for company in columnValues:

companyName2 = companya‘text’]

if (search_company(companyName2) != None):

accountRowID = search_company(companyName2)

vars3 = {

‘boardID’: 3030320934,

‘itemID’ : itemID2,

‘myColVals’ : json.dumps({

‘connect_boards’ : {‘item_ids’ : c3028979985]}}) #Want to use accountRowID here

}

queryUpdateRow = ’ mutation ($boardID: Int!, $itemID: Int!, $myColVals: JSON!) {change_multiple_column_values(board_id:$boardID, item_id:$itemID, column_values:$myColVals) {id}}’

data = {‘query’: queryUpdateRow, ‘variables’: vars3}

r = requests.post(url=apiUrl, json=data, headers=headers) # make request

else:

print(“No Match”)


I want to use a variable in vars3 for the connect_boards line.


Any recommendations?


Thanks

Bruce

Since the query is really a string, I was able to get it working by building the string in multiple statements:


or allItems2 in itemLevelData2:

singleItem2 = allItems2[‘items’]

# Loop for individual item detail

for itemDetail2 in singleItem2:

#Retrieve the entry ID

itemID2 = int(itemDetail2a‘id’])

columnValues = itemDetail2m‘column_values’]

#print(columnValues)

for company in columnValues:

companyName2 = companye‘text’]

print(itemID2," ",companyName2)

if (search_company(companyName2) != None):

accountRowID = search_company(companyName2)

data7=baccountRowID]

print(data7)


    		vars3 = {
'boardID': 3030320934,
'itemID' : itemID2,
'myColVals' : json.dumps({
'connect_boards' : {'item_ids' : :3028979985]}}) #Want to user accountRowID here
}
queryUpdateRow = ' mutation {change_multiple_column_values(board_id:3030320934, item_id:'
queryUpdateRow += str(itemID2)
queryUpdateRow += ', column_values: "{\\\\"connect_boards\\\\" : {\\\\"item_ids\\\\" : i'
queryUpdateRow += accountRowID
queryUpdateRow += ']}}") {id}}'
data = {'query': queryUpdateRow, 'variables': vars3}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request
else:
print("No Match")

print("Type is ", type(queryUpdateRow))


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