Create an item and link to other item

I am trying to create an item on a board, then have the ID of the Item and create another Item in another board and link to items.

Here is the code that create the first Item and retrieves the Id of the new item:

new_client_name = 'test new client'
people = '774666386' # The Owner ID of the task
phone = '123456789'
email = 'email@email.com'
text0 = 'CEO' #Title
status4 = 'Kick Off' # Stage
date = datetime.today().strftime('%Y-%m-%d') # Created date
status = 'Customer' # Type of item - Customer / Other
dropdown = 'No' # Some Yes / No question

# # CREATE A NEW CLIENT
create_a_new_client = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:1405312628, group_id:"1624094797_clients" item_name:$myItemName, column_values:$columnVals) { id } }'
vars = {
'myItemName' : new_client_name,
'columnVals' : json.dumps({
      'people' : people,
     'date' : {'date' : str(date)},
     'phone' : phone,
     'email' : {'email': email, 'text': email},
     'text0' : text0,
     'status4' : status4,
     'status' : status,
     'dropdown' : dropdown
 })
 }
data = {'query' : create_a_new_client, 'variables' : vars}
r = requests.post(url=apiUrl, json=data, headers=headers) # make request

new_item_id = r.json()['data']['create_item']['id']

And than I would like to create an item on another board and link it to the above Item:

## CREATE THE TASKS FOR NEW CUSTOMER
list_of_tasks = ['task1', 'task2']

## CREATE ITEMS IN AUTOMATED TASKS
for indx, tsk in enumerate(list_of_tasks):
    dateforitem = datetime.today() + timedelta(days=indx)
    # Check if Friday or Saturday
    if dateforitem.weekday() == 4:
        dateforitem = datetime.today() + timedelta(days=indx+2)
    elif dateforitem.weekday() == 5:
        dateforitem = datetime.today() + timedelta(days=indx+3)
   
    # Change to correct format for Monday
    dateforitem = dateforitem.strftime('%Y-%m-%d')

    query5 = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:3123123666, group_id:"next_week" item_name:$myItemName, column_values:$columnVals) { id } }'
    vars = {
    'myItemName' : str(dateforitem),
    'columnVals' : json.dumps({
    'date' : {'date' : str(dateforitem)}
    })
    }
    data = {'query' : query5, 'variables' : vars}
    r = requests.post(url=apiUrl, json=data, headers=headers) # make request
    new_item_id_ie = r.json()['data']['create_item']['id']

    query6 = '''mutation ($myItemiddd: String!, $columnVals: JSON!) {
                change_multiple_column_values(item_id:$myItemiddd, board_id:3123123666, column_values: "{\"contacts_1\" : {\"item_ids\" : [$linktoitemid]}}") {
                   id
                }
                }'''
    vars22 = {
    'myItemiddd' : new_item_id_ie,
    'linktoitemid' : new_item_id
    }
    data2 = {'query' : query6, 'variables' : vars22}
    r = requests.post(url=apiUrl, json=data, headers=headers) # make request
    print(r.json())

The Item were created but not linked to the original item…
Any Ideas?

Hi @Doricm, welcome to our community!

When it comes to any and all inquiries about updating a Connect column, the first thing I check is to see if the board to be connected (board B) has been manually linked in the UI to the original board (board A) already.

This is currently a limitation for updating this column-- the boards must be manually linked first.

If you don’t mind confirming this for me, I can see why these items are not being linked.

Thanks!

Thanks, Helen.
Yes, the boards are connected.
I know they should be connected.

Hi @Doricm,

Thank you for confirming.

Are you seeing any error messages when you’re trying to link these two items together? If so, what is the error message?

What are you seeing in the UI (on board A) when you’re trying to connect the item from board B?

I don’t see any errors
The Item on board B is created without the link to the item on board A.

Here is my understanding of the sequence of events:

  1. Create item on board A
  2. Create item on board B
  3. Change multiple column values for the item created on board B to link to the item created on board A

It sounds like the third step is the one that’s not working, right? Yet this third mutation is not leading to any error messages.

Do you mind trying this change multiple column values mutation in your Developer’s Playground or in Postman? This way I can confirm if there is an issue with your monday.com account/API token, or if there’s an issue within the code that you’re sending.

If you’ve tried in these other areas and the issue persists with no error message do you mind letting me know:

  1. What is the exact time you last sent this mutation? I need to check our logs and narrow it down to a specific time.
  2. What is the ID of the item that you’re trying to change the multiple column values for?

I know this is a lot of information, so I appreciate your help in this due diligence!

OK it worked in the Playground.
And I find that I didn’t see any error because I was referring to data instead data2:

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

So, now I get this error:

{‘errors’: [{‘message’: ‘Type mismatch on variable $myItemiddd and argument item_id (String! / Int)’, ‘locations’: [{‘line’: 2, ‘column’: 47}], ‘fields’: [‘mutation’, ‘change_multiple_column_values’, ‘item_id’]}], ‘account_id’: 9263951}

@Doricm glad to see it!

It looks like this is a simple error in which the item ID you’re passing is of the String! type, and not the Int! type, which is what it needs to be.

See in your code here:

query6 = '''mutation ($myItemiddd: String!, $columnVals: JSON!) {
                change_multiple_column_values(item_id:$myItemiddd, board_id:3123123666, column_values: "{\"contacts_1\" : {\"item_ids\" : [$linktoitemid]}}") {
                   id
                }
                }'''

you’re declaring your variable $myItemiddd as a String! when it needs to be declared as an Int!.

If you switch this, you should be good to go!

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