I fabricated some better data. Maybe that will help shed some better light. Also, here is some more code on how I am constructing the data to be fed into the create_sub_item function I have above. This run shows that the sub item title wasn’t constructed at all, but a subitem was in fact created. Sometimes the title is constructed and sometimes not.
Strangely, every time I create a sub item, I get one Internal server error, status code == 500
message. That is the purpose for my while
loop below. It only happens once, so if I were to not sys.exit()
out, the other two groups would not encounter that error.
# Query each group and create a subitem for item
query_group_id = f"""
{{
boards (ids: {dup_board_id}) {{
groups {{
title
items_page (limit: 50) {{
cursor
items {{
id
name
column_values {{
id
value
}}
}}
}}
}}
}}
}}
"""
data = {'query' : query_group_id}
r = requests.post(url=apiUrl, json=data, headers=headers)
r_dict = r.json()
print(r_dict)
group_board_info = r_dict['data']['boards'][0]['groups']
print(group_board_info)
# Iterate through each group, skipping the first item. First item is skipped since that will be the "parent item"
# Copy column values and names to be created as a subitem for the parent item (relative to that group)
for dictionary in group_board_info:
print(dictionary)
items = dictionary['items_page']['items']
print(items)
for cnt, item in enumerate(items):
if cnt == 0:
parent_item_id = item['id']
continue
cv = item['column_values']
subitem_name = item['name']
column_value_dict = {}
for d in cv:
column_value_dict[d['id']] = d['value']
print(item)
print(parent_item_id)
print(cv)
print(subitem_name)
print(column_value_dict)
# Internal server error (unknown)
run_again = True
while run_again:
r = create_subitem_for_item(parent_item_id, subitem_name, column_value_dict)
if r.status_code == 500:
time.sleep(1)
print('Internal server error found')
else:
run_again = False
sys.exit()
Print Outputs
>>>
r_dict:
{'data': {'boards': [{'groups': [{'title': 'Home - Mortgage - Oceans 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Oceans 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Imagery', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Home - Mortgage - Ground 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Ground 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': '2000.1 - 2000.1 Vegetation', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Hours"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Home - Mortgage - Mountains 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Mountains 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Detection', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Group Title', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Task 1', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}]}}]}]}, 'account_id': 12345}
group_board_info:
[{'title': 'Home - Mortgage - Oceans 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Oceans 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Imagery', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Home - Mortgage - Ground 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Ground 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': '2000.1 - 2000.1 Vegetation', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Hours"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Home - Mortgage - Mountains 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Mountains 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Detection', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial"'}, {'id': 'compensation', 'value': '"0"'}]}]}}, {'title': 'Group Title', 'items_page': {'cursor': None, 'items': [{'id': '5597071563', 'name': 'Task 1', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}]}}]
dictionary:
{'title': 'Home - Mortgage - Oceans 2023', 'items_page': {'cursor': None, 'items': [{'id': '12345', 'name': 'Oceans 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Imagery', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]}]}}
items:
[{'id': '12345', 'name': 'Oceans 2023', 'column_values': [{'id': 'phase', 'value': None}, {'id': 'compensation', 'value': None}]}, {'id': '12345', 'name': 'Imagery', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]}]
item:
{'id': '12345', 'name': 'Imagery', 'column_values': [{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]}
parent_item_id:
12345
cv:
[{'id': 'phase', 'value': '"1000 - 1000 Geospatial : Work"'}, {'id': 'compensation', 'value': '"0"'}]
subitem_name:
Imagery
column_value_dict:
{'phase': '"1000 - 1000 Geospatial : Work"', 'compensation': '"0"'}
function variables:
{'itemId': '12345', 'subItemName': 'Imagery', 'columnValues': '{"phase":"\\"1000 - 1000 Geospatial : Work\\"","compensation":"\\"0\\""}'}
function .json():
{'data': {'create_subitem': {'id': '12345'}}, 'account_id': 12345}