Are you using our SaaS platform (Baserow.io) or self-hosting Baserow?
Self-hosted
If you are self-hosting, what version of Baserow are you running?
Version 1.33.4
What are the exact steps to reproduce this issue?
Hi!
I’m using Python to work with our Baserow API.
I’m trying to figure out how to change the values of multiple and single choice fields but it’s not working.
In the Baserow API documentation there is a part for get/update/delete/duplicate fields (Baserow API spec) but I can’t find it in our self-hosting API documentation and it also doesn’t work, when I try the general docu (see above).
I’m able to update rows and the config for the API key is right.
I also tried to do it with a small database hosted with baserow cloud but this also didn’t work.
What can I do to update the lists with API?
Thanks for your help!
Hi @rensinghoff, could you share the code you are using to try and update the field options?
What should be happening:
- Get the table fields
curl -X GET
“``https://api.baserow.io/api/database/fields/table/{table_id}/”``
-H “Authorization: JWT {your_token}”
-H “Content-Type: application/json”
- Update single select options
curl -X PATCH
“``https://api.baserow.io/api/database/fields/{field_id}/”``
-H “Authorization: JWT {your_token}”
-H “Content-Type: application/json”
-d ‘{
“select_options”: [
{“value”: “Option 1”, “color”: “blue”},
{“value”: “Option 2”, “color”: “red”},
{“value”: “New Option”, “color”: “green”}
]
}’
- Multi select options
curl -X PATCH
“``https://api.baserow.io/api/database/fields/{field_id}/”``
-H “Authorization: JWT {your_token}”
-H “Content-Type: application/json”
-d ‘{
“select_options”: [
{“value”: “Choice A”, “color”: “purple”},
{“value”: “Choice B”, “color”: “orange”},
{“value”: “Choice C”, “color”: “yellow”}
]
}’
Thanks for your reply!
I’m using Python so it looks a little bit different. But I just realised that if I’m trying to call https://api.baserow.io/api/database/fields/{FIELD_ID}/ (in the Baserow Cloud and also in the self hosted version but I don’t want to post the URL here) I get an 401 error, even in the get
So I think this is where the problem starts…
But I’ll paste the code I have:
requests.get(
"https://api.baserow.io/api/database/fields/table/1234/",
headers={
"Authorization": "Token abc"
}
) # This works, I get a 200.
data_field = {
"name": "object",
"select_options": [
{
"value": "tree", # this value exists, I just want to change the color
"color": "green"
}
]
}
requests.patch("https://api.baserow.io/api/database/fields/45678/",headers={"Authorization": "Token abc"},
json=data_field) # This throws a 401
Thank you!
What role do you have in the workspace? 401 error indicates a permissions issue - meaning you might not have the required permission to mkae that change to the field.
I’m Admin in both, is there a role higher than this?
No, indeed that’s the highest. I’m not sure why you would be getting this error then. I will have to ask the team internally about this.
1 Like
Hey @cwinhall !
Did you hear anything from the team? Thank you! 
Hi @rensinghoff sorry for the delay.
I noticed that in your previous code, you’re using “Token" abc” for the auth header’s value but with this endpoint you should be using the JWT token (Example provided in my previous response) as this is the backend API - not the database API (which uses the database token).
To get the JWT token you need to auth using your email and password as outlined here: Baserow API spec
1 Like
Thank you! It works I’ll post the code for others to follow:
# Login with JWT Token
login_url = "https://api.baserow.io/api/user/token-auth/" # change URL
API_TOKEN = {"email": "abc", # add mail address
"password": "abc"} # add pw
resp = requests.post(login_url, json=API_TOKEN)
print("Status Code:", resp.status_code)
print("Answer as text:", resp.text)
token = resp.json()["token"]
headers = {"Authorization": f"JWT {token}"}
# Change select options of field
FIELD_ID = 1234 # add field ID
url_fieldid = f"https://api.baserow.io/api/database/fields/{FIELD_ID}/"
response = requests.get(url_fieldid,headers=headers)
if response.status_code == 200:
field_info = response.json()
print(field_info)
else:
print("Erros:", response.status_code, response.text)
data_field = {
"name": "objectcat",
"select_options": [
{
"value": "tree", # this value exists, I just want to change the color. Please be aware that this will overwrite existing select options. So if you have some already, add them here.
"color": "green"
}
]
}
response = requests.patch(url_fieldid, headers=headers, json=data_field)
if response.status_code == 200:
print("Field patched!")
print(response.json()) # new propterties
else:
print("Error:", response.status_code, response.text)
1 Like