Creating a new item with color columns updated

I have a dashboard in which I am creating new items with a Python script.

The group I am creating items in has columns I would like to be populated with data as soon as an item is created.

This is an example of how i’d like one of the columns to look after creating the item (This was done manually):

 "column_values": [
      {
        "id": "status_2",
        "title": "Who has the ball",
        "text": "Customer",
        "value": "{\"index\":7,\"post_id\":null,\"changed_at\":\"2021-02-17T09:16:52.085Z\"}",
        "type": "color",
        "additional_info": "{\"label\":\"Customer\",\"color\":\"#fdab3d\",\"changed_at\":\"2021-02-17T09:16:52.085Z\"}"
      },

This is the code, which is obviously not working:

query = 'mutation ($myItemName: String!, $columnVals: JSON!) ' \
        '{ create_item (board_id:%s, group_id:"%s", ' \
        'item_name:$myItemName, column_values:$columnVals) { id } }' % (
            board_id, group_id)

data = {'query': query, 'variables':
    {'myItemName': task_name,
     'columnVals': json.dumps([{'date4': {'date': str(date.today())}},
                               {"status_2": "{\"label\":\"Customer\",\"color\":\"#fdab3d\"}"}])}
        }

res = requests.post(url=MONDAY_API_URL, json=data, headers={"Authorization": MONDAY_API_TOKEN})

It creates an item with the columns i’d like updated blank (The date4 is created Ok).

Any help would be appreciated.

hi @Yuval_C

Unfortunately the API does not support adding labels and/or colors to status (color) columns. When you query a status column you can see it has a settings_str value, but you can’t change that value with an API call.

1 Like

Hi @Yuval_C!

Hmm strange. Not sure why only the Status column would not be pulling through, but can we try a few things to see if it helps, in addition to Bas’s suggestion?

  1. The column values need to be separated by only a comma, and it looks like you’re performing json.dumps() on an array of column values you’re hoping to change. Maybe try performing separate dumps methods on date4 and status_2 that are only separated by a comma?
  2. Make sure the formatting between date4 and status_2 match exactly – so I see date4 is single, not double quotations, and also you did not include quotation marks around the outside of the value of the date4 key-value pair.
  3. It looks like your status_2 values are already in JSON formatting-- why are you converting it again?

Wasn’t sure if all of these would be helpful, but this is what I’m thinking about.

-Helen

If this can’t be done while creating a new item, how can I do it using mutations? I tried but couldn’t get it to work and documentation is very basic.

Hi @Yuval_C,

Are you specifically looking to set the color when mutating the status column?

If not, you can just reference the status label itself, and the color will likewise be set because it’s associated with the status label itself.

Do you mind expanding on why you were looking to alter the color specifically?

-Helen

I have an automation in python that creates items when external events occur. All these items should be tasked to the same person (I know I didn’t ask this but I need to set this too) and have the same status.
The column for setting the person:

{
     "id": "person",
     "value": "{\"personsAndTeams\":[{\"id\":172342122,\"kind\":\"person\"}],\"changed_at\":\"2021-02-17T09:14:22.336Z\"}",
     "title": "Owner"
}

I will try setting the status and see if that works.
Is there a way to set the person column as well?

Thank you Helen.

Hi @Yuval_C,

You can mutate the value of a People column by entering the person Id only.

It might help for you to check out the API section explaining our People column: API v2 Documentation.

Hope this helps!

-Helen