Variable Mismatch on variable column_type

Having some trouble trouble shooting my error. I’ve read through a few other solutions to what I believe the problem I am having, but have yet to find a solution. Is column_type not a String?

I am creating columns with the following code:

Note, I am using python=3.10

def create_columns(board_id, title, column_type, default_values=None):
    if default_values:
        vals_dict = {}
        for cnt, vals in enumerate(default_values):
            vals_dict[cnt + 1] = vals
        status_values = {"labels": vals_dict}
    else:
        status_values = ''

    query = """
    mutation ($boardId: ID!, $titleName: String!, $columnType: String!, $defaultValues: JSON) {
        create_column(
            board_id: $boardId
            title: $titleName
            column_type: $columnType
            defaults: $defaultValues
        ) {
            id
        }
        }
    """

    variables = {
    'boardId': board_id,
    'titleName': title,
    'columnType': column_type,
    'defualtValues': json.dumps(status_values, separators=(',', ':'))
    }

    datas = {
    'query': query,
    'variables': variables
    }

    r_boards = requests.post(url=apiUrl, headers=headers, data=json.dumps(datas)) # make request
    
    return r_boards

variables

>>>{'boardId': '123456', 'titleName': 'My - Title', 'columnType': 'status', 'defualtValues': '{"labels":{"1":"100 - column1","2":"200 - column2","3":"300 - column,,3"}}'}

Error Message

>>>{'errors': [{'message': 'Type mismatch on variable $columnType and argument column_type (String! / ColumnType!)', 'locations': [{'line': 6, 'column': 13}], 'path': ['mutation', 'create_column', 'column_type'], 'extensions': {'code': 'variableMismatch', 'variableName': 'columnType', 'typeName': 'String!', 'argumentName': 'column_type', 'errorMessage': 'Type mismatch'}}], 'account_id': 123456}

Simple enough, the answer is in the error message, define $columnType: ColumnType! instead of String! for your mutation. This is because column types are now an enum ColumnType rather than just strings.

Also in your variables you misspelled defaultValues as defualtValues which will cause an error later on.

If you look at the documentation for create_column you can see the arguments and their types, and column_type is of the type ColumnType.

lastly, I learned something about request.post is that it can take a json parameter instead of data and an object provided to json gets converted to json automatically - no needs to use json.dumps

2 Likes

Thanks for pointing that out Cody. Glad it was so simple. I tried to match it against our last discussion and was confused why it wasn’t working. Thanks for pointing out the misspelling as well. I tried removing the json.dumps but failed with a Requests json Decode Error. Put it back in and it worked. Not if that is due to a pythonic issue/format.

Again, thanks for you help. Guess you will be helping me on all my monday.com api questions lol!

Okay you’re on my blacklist now! No help from me until someone else steps up! Kidding! Glad we got it sorted. But yeah, if you can figure out how to interpret the error messages, it goes a long way.

1 Like

I agree. The more time I spend working with it, the better I should get. Just need those few pointers here and there to initially learn.

Hey Cody, I do have a follow up question. Not sure if I need to post a new question. I’ve noticed that if I have more than 5 defaultValues then the fifth index is used as a place holder within the board. However, if I have fewer than 5 defaultValues then an additional blank default value is automatically created to act as the place holder. Not sure if you have seen or ran into this before. I have not come across anything on monday’s create column documentation yet.

I was able to use a work around and just skip the fifth index value, but that just seems a little silly to me.

index 5 is the gray default, oddly not 0 or 1. You can’t change it.

2 Likes

Thank you @codyfrisch for the help here!

1 Like