Python requests change_column_value (or change_multiple_columns) of subitem in sub-board

I am currently unable to write to a subitems column. If you know, change_multiple_columns would be preferred. The examples of the documentation do not help me as the devil is in the json formatting and parameter passing. If you know a python code that works for this, I would be so happy.
Among 3000 versions, I tried the following:

        sub_data = {
                "url": "http://example.com",
                "text": "website"
        }

        mutation_query = '''
        mutation(
            $itemId: ID!,
            $boardId: ID!,
            $columnId: String!,
            $colValue: JSON!) {
                change_column_value(
                    item_id: $itemId,
                    board_id: $boardId,
                    column_id: $columnId,
                    value: $colValue) {
                    id
                }
        }
        '''

        response = requests.post(params["api-url"], headers=headers,
                                json={
                                    "query": mutation_query,
                                    "variables": {
                                        "itemId": int(sub_id),                                        
                                        "boardId": int(sub_board_id),
                                        "columnId": "link",
                                        "colValue": json.dumps(sub_data)
                                    }
                                }
                                )

To get the subitem board id, I used the following:

        query = """
        query {
            items (ids: %i) {
                parent_item  {
                    id
                }
            }
        }
        """ % (int(sub_id))

        response = requests.post(params["api-url"], headers=headers,
                                  json={"query": query})

The error is response.status 500, the html with “We are having technical issues
Please visit our Status Page for updates. We apologize for any inconvenience.” although the status website shows that everything should be ok

1 Like

Posting the errors you get would be quite useful. Usually they minimally tell you the issue. If it seems to “silently” fail thats not true, GraphQL returns its errors in a 200 response so your client will not throw an exception. You need to log out the response itself to get the error.

1 Like

yes, sorry, now added something but not sure if helpful. If there is a specific test you think would be telling - or if someone amazingly just knows how to write to a subitem column via api and python - please tell me

I see how you’re getting the subitem board ID… and it makes no sense to me because no board ID is being returned. In that second query, what item ID are you providing? Assuming the subitems item ID is the one youre querying, The parent_item ID is just the ID of the parent item on the parent board.

query (items (ids: %i) {
 id
 board {
  id
 }
}

That query, data.items[0].board.id would the subitems board ID, assuming the item ID you queried is the subitem ID.

The method to get the subitem board id via the parent was given by a monday team meber here: How to determine whether a board is a subitem board via the API - #3 by TomUK
But you are right, and your method now works! I must have made a mistake when this gave me the main board id earlier.
However, my main question still remains and even with that sub board id, I get the same error page

Ah, thanks to your help, I now got more meaningful error messages again and it turns out that my json for the url data was incomplete. With this one (and the above query code) it now works:

        sub_data = {
                "link": {"url": "http://example.com",
                        "text": "website"}
            }

Thanks for your fast help again!

That JSON you provided is for the change_multiple_column_values mutation but your original code showed change_column_value so I didn’t think it would be incorrect. Just an FYI link in your new one is the column Id so you may want to use your column ID in question as the key rather than hard coding “link”

Ah ok, thanks for the additional info! “link” is what the guy who created the board thought would be a good ID :sweat_smile:

its also the default for the first Link column created on the board, you don’t really get a choice in column ID when you create a column via UI - only the API.

1 Like

ah ok, so its not his fault, its the monday UI that creates these ids like “text” and then “text17”

1 Like

yes, you cannot specify the ID when you create a column by UI. You can specify it when you do it by API though. If developing an app for general consumption, you would never code any IDs in, its okay if its a one off specific use case.

1 Like