API update clearing values from a single and multi select

I am using python with request module for editing the values of certain fields.
All looks great until I have to remove all the values from a single or a multi select: I can keep editing/adding values but I cannot clear the values. Is there a particular argument that I have to provide to the patch request in order to remove all the values from the field?
Any pointer? Thanks in advance :slight_smile:

Hi @franfran, are you looking to delete the select options of a field or the selected select option value of a row? In either scenario, I can provide an example:

To remove the select options of a field, you can make a patch reuqest to the update field endpoint. Make sure that you remove the select_options in the JSON body payload. In the example below, I’m removing all the select options.

PATCH /api/database/fields/{field_id}/
   "name":"Multiple select",

When updating a row, it works similarly. Just make a patch request to the row update endpoint, and make sure that you provide the field you would like to clear in the body. For multiple select you can provide an empty array, and for single select null.

PATCH /api/database/rows/table/{table_id}/{row_id}/
  "{multiple_select_field_id}": [],
  "{single_select_field_id}": null

I hope that helps!

Hey @bram , thanks for the prompt and imformative answer.
I am afraid that I am not able to carry in python your solution :confused:

In my code I tried this one

r = requests.patch("https://api.baserow.io/api/database/rows/table/xxxxxx/6/?user_field_names=true",
                       {"root rotation": []},
                       headers={"Authorization": "myFancyToken"}

Where 6 in the URL is the record ID and "root rotation" is the multi select field that I want to reset for that record
Do you see any flaw in my script? There must be something very basic that is eluding me :frowning:
Thanks again for your kind and prompt help.

Hi @franfran, what does the response say? From just looking at your code, your authorization header should look like headers={"Authorization": "Token myFancyToken"}, but the response should tell you what’s wrong.

Hey @bram,|
I got a <Response [200]> so everything should have been fine. but the value in the field didn’t change :frowning:

Hey @bram,
For what concern the single select field I noticed that for reset it I have to pass an empty string as value in the payload json-like object: {mySingleSelectField: ""} . So we are one issue down :smiley:
About the Multiple Select I tried several ways.
Some of those gave as response <Response [400]>:

  • passing an empty string: ""
  • passing an empty string in a list: [""]
  • passing anull as string: "null"

Some other gave me as response <Response [200]> but with no changes in the field value:

  • passing None
  • passing an empty list, as you suggested []
  • passing None in a list[None]
  • passing an empty dictionary in a list [{}]

Then I tried to set a different value for ?user_field_names and try to use the field and value codes to add and change values of the multiple select field in question. I noticed that despite the <Response [200]> that setup didn’t produced any editing in the database.
I am on a free plan, might be some profile/workspace setup that is causing those problems?

It shouldn’t matter whether you’re on the free plan. I’m 100% sure that passing {myMultipleSelectFIeld: []} should work for you. This is how our web-frontend is also communicating to the API, and otherwise, it would not be possible to clear the value there.

I would be able to give you better advice if you post the full request you’re making.

Hey @bram ,
Thanks for your prompt reply. I am as much puzzled as you are…
Here follows the general function that I am using for patching records.

def patching_record(id, field, value):
    r = requests.patch("https://api.baserow.io/api/database/rows/table/XXXXXX/{}/?user_field_names=true".format(id),
                       {field: value},
                       headers={"Authorization": "hereGoesTheToken"}

    return r

Which is the same of the hardcoded snippet that I added in the my second post (third overall) of this convo.

r = requests.patch("https://api.baserow.io/api/database/rows/table/xxxxxx/6/?user_field_names=true",
                       {"root rotation": []},
                       headers={"Authorization": "myFancyToken"}

I am not experienced in doing http calls with python but as far as I investigate the matter I cannot see much more to add… or there is and that could be my problem :slight_smile:

The other thing that I was thinking is that it might be a problem with the Google Chrome, but it seems quite far fetched.

Thanks for your help

Can you please share a screenshot of the table in the web-frontend, including the root rotation field?

Hey @bram,
Thanks for following up this issue. Here comes a quick screen capture of my database.
I really cannot get why is not working.
If necessary I can give you also private access to the workspace.
Thanks again

Hi @franfran, to figure out what’s going wrong, I would need to have API access to your table. If it’s a possibility for you, would you mind sharing the full request including the API token, table ID, etc with me privately? Then I should be able to reproduce your exact scenario.

Good morning @bram ,
Sure thing, I am going to send you a private message with all the data that you need. Thanks for your kind help.