Getting columns name

Hi everyone,
So I have this Python code:

query = ‘mutation ($myBoardID: Int! , $myItemName: String!, $columnVals: JSON!) { create_item (board_id:$myBoardID, item_name:$myItemName, column_values:$columnVals) { id } }’
vars = {
‘myItemName’: serverName,
‘myBoardID’: self.board_id,
‘columnVals’: json.dumps({
‘status’: {‘label’: str(status[0])},
‘status1’: {‘label’: str(status[1])},
‘status2’: {‘label’: str(status[2])},
‘date4’: {‘date’: str(datetime.date(datetime.now()))},
‘Error’: {‘text4’: Error}
})
}

Unfortunately I can only write to date and status.
How can I know the name of the column in order to write to it?

p.s.
The name of the column I used ‘status’ to fill is not status.
Can I even fill via code more than one status column?

Thanks for your help

1 Like

hi @shanix.guttman

Welcome to the community! You can get the columnIds by querying the board with:

{
  boards(ids: 123456789) {
    columns {
      id
      title
    }
  }
}

columnIds are generated by monday and you can’t rely on id’s like status, status1, status2 etc., most likely the second status column has an id status_1 but it depends on earlier actions on that board. Therefore you should always query the board for the columnIds.

In the UI you can find these columnIds by enabling the monday.labs developers feature. With that enable the columnId is shown when you click the little down arrow in the column header.

2 Likes

That was very helpful. thanks!

1 Like

Hi @basdebruin ,
I have another question - is there a way to decide on the columnIds when creating a new column?
Do you have an example for creating a new status column and deciding on its columnId and its lables?

kind regards,
Shani

Hello @shanix.guttman and welcome to the community :muscle:

Thank you @basdebruin for the knowledge as usual :crown:

You can not decide which ID the column will have. The column ID is generated automatically by monday.

Please let us know if you have any other questions :slightly_smiling_face:

Cheers,
-Matias

hi @shanix.guttman

As @Matias.Monday said, columnIds are generated by the platform itself and you can’t change those. However, if you create a column through the API the columId will be the same as the column title (no capitals and spaces replaced by underscores ‘_’), but only when the columnId is not in use on the board.

So, if you create a column with title “Brand New Column” I bet the columnId will be ‘brand_new_column’. No guarantees :slight_smile:

As for creating a status column you can use:

mutation {
  create_column(board_id: 123456789, column_type: status, title: "My New Status") {
    id
    type
  }
}

it returns this:

{
  "data": {
    "create_column": {
      "id": "my_new_status",
      "type": "color"
    }
  },
  "account_id": 123456
}

As you see the columnId is now “my_new_status” (as expected). Take care: a status column returns its type as color. A little inconsistency here :slight_smile:

Now for the labels. You can add labels, but you can delete them. You do this by a mutation on an item and setting “create_labels_if_missing” to true, like:

mutation {
  change_column_value(board_id: 123456789, item_id: 987654321, column_id: "my_new_status", value: "{\"label\":\"New Label\"}", create_labels_if_missing: true) {
    id
  }
}

This creates a new label “New Label” and set it for that item, all other items can now also pick that label. The default labels will still be there, you can only change them by changing the default labels for any new status column in the account, found by clicking Avatar > Admin > Customization > Boards

Hope this helps.

Bruh honestly to you and everybody using the api I highly recommend the Monday python library

It will let you do everything you’re trying to do and more so easily

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