It seems odd to me, there seems to be too many " marks around the values in column values. Like every string includes the quotes. Which may cause errors with number columns.
What I do know is your query is correct, so the issue is in the formatting of the values. My only thought is your strings going into the have quotes in them and they shouldn’t - particularly the numbers.
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_dictc'data']''boards']'0]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 = dictionaryr'items_page']''items']
print(items)
for cnt, item in enumerate(items):
if cnt == 0:
parent_item_id = iteme'id']
continue
cv = iteme'column_values']
subitem_name = iteme'name']
column_value_dict = {}
for d in cv:
column_value_dictcd['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}

Hello there @Binx96,
I am not experienced with Python, but your mutation does look correct.
Something like this is valid:
mutation ($itemId: ID!, $subItemName: String!, $columnValues: JSON) {
create_subitem (
parent_item_id: $itemId,
item_name: $subItemName,
column_values: $columnValues
create_labels_if_missing: true
) {
id
}
}
{
"itemId": 1234567890,
"subItemName": "Some name",
"columnValues": "{\\"text\\":\\"Some text\\", \\"numbers\\":\\"100.1\\"}"
}
Postman translates this to Python as:
import http.client
import json
conn = http.client.HTTPSConnection("api.monday.com")
payload = "{\\"query\\":\\"mutation ($itemId: ID!, $subItemName: String!, $columnValues: JSON) {\\\\n create_subitem (\\\\n parent_item_id: $itemId,\\\\n item_name: $subItemName,\\\\n column_values: $columnValues\\\\n create_labels_if_missing: true\\\\n ) {\\\\n id\\\\n }\\\\n } \\",\\"variables\\":{\\"itemId\\":1234567890,\\"subItemName\\":\\"Some name\\",\\"columnValues\\":\\"{\\\\\\"text\\\\\\":\\\\\\"Some text\\\\\\", \\\\\\"numbers\\\\\\":\\\\\\"100.1\\\\\\"}\\"}}"
headers = {
'API-Version': '2023-10',
'Authorization': 'APITOKENHERE',
'Content-Type': 'application/json',
}
conn.request("POST", "/v2/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
I hope that helps!
Cheers,
Matias
@Matias.Monday
Looked through your mutation, but still no luck. I copied your postman example and replaced it with my ids and data. Columns and values were still not being populated. The default columns when creating a subitem were only present.
I’ve also tried running it straight from the playground. Same results as above (item names are populated, but columns/column values do not change).
I am running out of ideas. Should I submit a ticket to your IT support?
import requests
apiKey = '...'
apiUrl = "https://api.monday.com/v2"
headers = {"Authorization" : apiKey,
"Content-Type" : 'application/json',
"API-Version" : '2023-10'}
# My payload
payload = "{\\"query\\":\\"mutation ($itemId: ID!, $subItemName: String!, $columnValues: JSON) {\\\\n create_subitem (\\\\n parent_item_id: $itemId,\\\\n item_name: $subItemName,\\\\n column_values: $columnValues\\\\n create_labels_if_missing: true\\\\n ) {\\\\n id\\\\n }\\\\n } \\",\\"variables\\": {\\"itemId\\": 12345,\\"subItemName\\":\\"Imagery\\",\\"columnValues\\":\\"{\\\\\\"phase\\\\\\":\\\\\\"1000 - 1000 Geospatial\\\\\\", \\\\\\"compensation\\\\\\":\\\\\\"0\\\\\\"}\\"}}"
# Your payload example
# payload = "{\\"query\\":\\"mutation ($itemId: ID!, $subItemName: String!, $columnValues: JSON) {\\\\n create_subitem (\\\\n parent_item_id: $itemId,\\\\n item_name: $subItemName,\\\\n column_values: $columnValues\\\\n create_labels_if_missing: true\\\\n ) {\\\\n id\\\\n }\\\\n } \\",\\"variables\\":{\\"itemId\\":1234567890,\\"subItemName\\":\\"Some name\\",\\"columnValues\\":\\"{\\\\\\"text\\\\\\":\\\\\\"Some text\\\\\\", \\\\\\"numbers\\\\\\":\\\\\\"100.1\\\\\\"}\\"}}"
r_boards = requests.post(url=apiUrl, headers=headers, data=payload)
print(r_boards.json())
Monday.com Playground
mutation {
create_subitem (
parent_item_id: 12345
item_name: "Test_Name"
column_values: "{\\"phase\\":\\"1000 - 1000 Geospatial : Work\\", \\"compensation\\": \\"0\\"}"
create_labels_if_missing:true
) {
id
}
}
Hi @rachelatmonday ,
Thanks for confirming. Absolutely I can share!
Lets use my original post as an example. Image one is a board that contains multiple groups with a range of 1-50 items. The second image is another board with one group. Board_2 items will be the name of each group from board_1. The subitems of each item are the items from board_1 in respect to their group. Image 2 illustrates that better.
My current solution:
- Duplicate board_1
- Create the “Active Projects” group
- Create an “initiate” subitem to allow adding and removing of it’s columns
- For each group:
a. Create an item of the group name
b. Create an subitem for each item in the group
c. Delete the item once it’s subitem is created
d. Once all subitems are created, move the item (with subitems) up to “Active Projects”
e. Delete group
Wanted solution:
- Create new board
- Create “Active Projects” group
- Create columns/types
- Create items based on group names from board_1 (already built in my code).
- Move the items from board_1 to subitems in board_2 in respect to their group
When working with a small dataset, current solution works just fine. However, when working with several thousands of items. Each create, delete, move step takes a few seconds. Moving an item to a specific location takes significantly less time (my hope) then duplicating it, re-creating it as a subitem, deleting the original and moving it to another group.
Subitems already has it’s own board id, so I would think it would be trivial to be able to move an item between two boards so long as they have the same columns.
Hope that makes sense and feel free to ask any clarifying questions.