Manage user preferences
Preferences belong to the signed-in user. You can read and update only your own
preferences, not another user's. Configure
an authenticated client using
the JavaScript setup or Python setup.
taruvi below is the configured JavaScript client, and client is the
synchronous Python client. Preferences are separate from user attributes and
don't affect access. A
client that uses an API key reads and writes the preferences of the key's
creator, so use the user's session to change theirs.
Preference fields#
The first GET auto-creates a preference record with these defaults when none
exists.
| Field | Default | Accepted value |
|---|---|---|
date_format | YYYY-MM-DD | YYYY-MM-DD, DD/MM/YYYY, MM/DD/YYYY, DD-MMM-YYYY |
time_format | 24h | 24h, 12h |
timezone | UTC | Valid IANA timezone name, such as Asia/Kolkata |
theme | light | light, dark |
widget_config | {} | Application-defined settings in any JSON object |
Read and update preferences#
An update changes only the fields you send and creates the preference record if it doesn't exist yet.
- JavaScript SDK
- Python SDK
- REST API
import {User} from '@taruvi/sdk';
const users = new User(taruvi);
await users.getPreferences();
await users.updatePreferences({theme: "dark", timezone: "Asia/Kolkata"});
await users.getPreferences();
client.users.get_preferences()
client.users.update_preferences({"theme": "dark", "timezone": "Asia/Kolkata"})
client.users.get_preferences()
/api/users/me/preferences/Headers
AuthorizationApi-Key $TARUVI_API_KEY
View cURL
curl "$TARUVI_SITE_URL/api/users/me/preferences/" \
-H "Authorization: Api-Key $TARUVI_API_KEY"
200
/api/users/me/preferences/Headers
AuthorizationApi-Key $TARUVI_API_KEYContent-Typeapplication/json
Request body
{
"theme": "dark"
}
View cURL
curl -X PUT "$TARUVI_SITE_URL/api/users/me/preferences/" \
-H "Authorization: Api-Key $TARUVI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<'JSON'
{
"theme": "dark"
}
JSON
200
Verify and recover#
Re-read after an update and compare the returned values with the intended
change. If the API rejects an invalid date format, time format, timezone, or
theme, correct the rejected value, retry the update, then re-read the
preferences. A 401 means the user's credential is missing or expired.
For other problems, see troubleshooting.