Issue programmatically/api creating choice list (choices don't get created)

I’m adding columns with choices ‘True’, ‘False’
(side note: i cannot use a Toggle since it casts None/Null to False, meaning I cannot disambiguate an unfilled value versus a False value).

I add using this code:

cid = {
   "id": col,
   "fields": {
   "type": "ChoiceList",
   "label": col,
   "widgetOptions": '{"widget":"TextBox","choices":["False", "True"],"choiceOptions":{"False":{"fillColor":"#00FF00","textColor":"#000000"}}, "headerFillColor": "#0057b8", "headerTextColor": "#FFFFFF" }'
 }
}
grist.add_cols(table_id="Domain_insight_summary", cols=[cid])

However, when done, I end up with no choices set. The column is created, the label is set, but the choice list is not populated.

can’t test it atm, but have you tried sending the widgetoptions as a single json encoded string?

In python, it calls:

(Pdb) json
{'columns': [{'id': 'MANUFACTURING', 'fields': {'colRef': 96, 'parentId': 9, 'parentPos': 96, 'type': 'ChoiceList', 'widgetOptions': '{"widget": "TextBox", "alignment": "left", "headerFillColor": "#0057b8", "headerTextColor": "#FFFFFF", "choices": ["True", "False"], "choiceOptions": {}}', 'isFormula': False, 'formula': '', 'label': 'MANUFACTURING', 'description': '', 'untieColIdFromLabel': False, 'summarySourceCol': 0, 'displayCol': 0, 'visibleCol': 0, 'rules': None, 'reverseCol': 0, 'recalcWhen': 0, 'recalcDeps': None}}]}
resp = request(method, url, headers=headers, params=params, json=json, **self.request_options)

this returns 400. it is a single string, json inside, e.g.:

'widgetOptions': '{"widget": "TextBox", "alignment": "left", "headerFillColor": "#0057b8", "headerTextColor": "#FFFFFF", "choices": ["True", "False"], "choiceOptions": {}}'
(Pdb) json['columns'][0]['fields']['widgetOptions']
'{"widget": "TextBox", "alignment": "left", "headerFillColor": "#0057b8", "headerTextColor": "#FFFFFF", "choices": ["True", "False"], "choiceOptions": {}}'

If i convert it manually back to json, still a 400.

If i manually modify it to one entry in the string:

(Pdb) json
{'columns': [{'id': 'MANUFACTURING', 'fields': {'colRef': 96, 'parentId': 9, 'parentPos': 96, 'type': 'ChoiceList', 'widgetOptions': '{"headerFillColor": "#0057b8" }', 'isFormula': False, 'formula': '', 'label': 'MANUFACTURING', 'description': '', 'untieColIdFromLabel': False, 'summarySourceCol': 0, 'displayCol': 0, 'visibleCol': 0, 'rules': None, 'reverseCol': 0, 'recalcWhen': 0, 'recalcDeps': None}}]}
(Pdb) resp = request(method, url, headers=headers, params=params, json=json, **self.request_options)
(Pdb) resp
<Response [400]>

its still 400

If i use the requests Prepare method of tracing:

PATCH https://grist.agilicus.ca/api/docs/TABLEID/tables/Domain_insight_summary/columns
Content-Type: application/json
Accept: application/json
Authorization: Bearer AUTHENTICATIONINFOREDACTED
Content-Length: 410

b'{"columns": [{"id": "MANUFACTURING", "fields": {"colRef": 96, "parentId": 9, "parentPos": 96, "type": "ChoiceList", "widgetOptions": "{\\"headerFillColor\\": \\"#0057b8\\" }", "isFormula": false, "formula": "", "label": "MANUFACTURING", "description": "", "untieColIdFromLabel": false, "summarySourceCol": 0, "displayCol": 0, "visibleCol": 0, "rules": null, "reverseCol": 0, "recalcWhen": 0, "recalcDeps": null}}]}'

reproducing with curl:

curl -v -X PATH -H "Content-Type: application/json" -H "Authorization: Bearer REDACTED" https://grist.agilicus.ca/api/docs/REDACTED/tables/Domain_insight_summary/columns -d '{"columns": [{"id": "MANUFACTURING", "fields": {"colRef": 96, "parentId": 9, "parentPos": 96, "type": "ChoiceList", "widgetOptions": "{\"headerFillColor\": \"#0057b8\" }", "isFormula": false, "formula": "", "label": "MANUFACTURING", "description": "", "untieColIdFromLabel": false, "summarySourceCol": 0, "displayCol": 0, "visibleCol": 0, "rules": null, "reverseCol": 0, "recalcWhen": 0, "recalcDeps": null}}]}'

I’ve tried with 1, 2, 3 backslash.

ok just to make sure, did you try PUTting back in the same json you got from GETting a column with the already configured choice list?

Yes I tried that too.

I am trying to problematically create columns. The front end does it over a websocket using a different API I think.

But i think i might be stymied by the rules later, they refer to something else I don’t see in the API.