Skip to main content

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.

FieldDefaultAccepted value
date_formatYYYY-MM-DDYYYY-MM-DD, DD/MM/YYYY, MM/DD/YYYY, DD-MMM-YYYY
time_format24h24h, 12h
timezoneUTCValid IANA timezone name, such as Asia/Kolkata
themelightlight, 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.

import {User} from '@taruvi/sdk';

const users = new User(taruvi);
await users.getPreferences();
await users.updatePreferences({theme: "dark", timezone: "Asia/Kolkata"});
await users.getPreferences();

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.