Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing error in ContactList column type #21

Open
APCBoston opened this issue Mar 8, 2023 · 2 comments
Open

Typing error in ContactList column type #21

APCBoston opened this issue Mar 8, 2023 · 2 comments

Comments

@APCBoston
Copy link

When I use smartsheet.Sheets.get_column() to retrieve a column whose type is CONTACT_LIST, the returned JSON payload improperly reflects a column type TEXT_NUMBER. If I then call update_column() to update the contact list, the API returns an error:

"errorCode": 1090, "message": "Column.type is required when changing symbol, systemColumnType, options, contactOptions, or autoNumberFormat.", "refId": "h3w1i3"

All well and good, but if I then call update_column() with type set to CONTACT_LIST, I get a different error:

{"result": {"code": 1087, "errorCode": 1087, "message": "The column specified is used in a conditional formatting rule, so the column cannot be deleted and its type cannot be changed.", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "vuhctf", "shouldRetry": false, "statusCode": 400}}

Of course, I don't WANT to delete the column or change its type -- the type should already be CONTACT_LIST. When looking at the column properties in the web app, the type is correct: CONTACT_LIST. But for some reason the API thinks it is a TEXT_NUMBER and thus makes it impossible to update the contact list options!

@TarekSalha
Copy link

TarekSalha commented Jun 15, 2023

I got into the very same problem as you did. Although, the issue is quite old, I want to post the solution to the problem:
the types CONTACT_LIST and MULTI_CONTACT_LIST are not retrieved due to the api being backwards compatible (see here).

you can change the compatibility level via retrieving the object_level field as well as setting the api level to 2

_client.Sheets.get_sheet(sheet_id=id, include=["columnType", "objectValue"], level=2)

be careful, the structure of the column will vary depending on the column types of your sheet. For writing back the value, you could do the following:

new_cell = smartsheet.models.Cell()
new_cell.column_id = column_mapper[update.column_name]
if update.column_type  == "MULTI_CONTACT_LIST":
    if update.value:
        new_cell.object_value = smartsheet.models.MultiContactObjectValue()
        new_cell.object_value.values = [smartsheet.models.ContactObjectValue(props={"email": mail.strip()}) for mail in update.value.split(",")] # assuming update.value to be of form "chuck@norris.com, someUser@test.com,..."
    else:
        new_cell.value = smartsheet.models.ExplicitNull()

hope this helps everyone stepping into the same problem :-)

@APCBoston
Copy link
Author

@TarekSalha thanks so much for posting your solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants