Hello!
I have two connected boards trying to connect one item in board1 with multiple items from board2. I’m using apiVersion = “2023-10”.
First of all, I tested this mutation in playground, and everything worked:
mutation{
change_multiple_column_values(item_id:123456, board_id: 123456, column_values: "{\\"link_to_another_board\\" : {\\"item_ids\\" : \123457, 123458, 123459]}}") {
id
}
}
But, when I try to implement this code into my Python script, there are some issues with strings, backslashes, and variables.
I only have 2 variables:
# The int, contains items id from board1:
new_item_id = r2.json()j'data']d'create_item']i'id']
print(f'New item id: {new_item_id}') --> New item id: 123456
#The list of items from board2, which must to be linked with item above:
print(f"linked_items: {linked_items}") --> linked_items: t123457, 123458, 123459]
Now, I need to make ‘mutation query’.
First, lets declare a variables for GraphQL schema:
graph_var_id = {"item_id": int(new_item_id), "linked_items": json.dumps(linked_items)}
print(f'graph_var_id: {graph_var_id}') --> graph_var_id: {'item_id': 1330819451, 'linked_items': '_123457, 123458, 123459]'}
It looks good, but I already don’t like the ‘’ around the 123457, 123458, 123459]
Ok, make query:
query_link_creation = 'mutation ($linked_items: JSON!, $item_id: Int!) {change_multiple_column_values(item_id: $item_id, board_id: 123456, column_values: "{\\" link_to_another_board \\" : {\\"item_ids\\" : $linked_items}}") {id}}'
Make data and request:
data3 = {'query': query_link_creation, 'variables': graph_var_id}
print(f'data3: {data3}') -->
data3: {'query': 'mutation ($linked_items: JSON!, $item_id: Int!) {change_multiple_column_values(item_id: $item_id, board_id: 123456, column_values: "{" link_to_another_board " : {"item_ids" : $linked_items}}") {id}}', 'variables': {'item_id': 123456, 'linked_items': 'l123457, 123458, 123459]'}}
And, of course, the lack of backslashes\\ it causes an error:
r3 = requests.post(url=apiUrl, json=data3, headers=headers)
print(f'r3: {r3.json()}') -->
r3: {'errors':
{'message': 'Parse error on " : {" (STRING) at 1, 151]', 'locations': '{'line': 1, 'column': 151}]}], 'account_id': 1111111111111}
But I really don’t know how to make this query. I already trying to use f-string (and become an errors, because f-string didn’t support backslashes), trying to use placeholders, and even this: my_string = f"This is a backslash: {chr(92)}".
I already read this topic:
But it didn’t help me.
Please, help me 🙂