Manage Account Preferences¶
Read the interface language and time zone settings of the authenticated account, submit updates, and re-read the preferences to confirm they took effect.
Task flow¶
SDK client account handle
│
▼
1. Read current account language (locale) and time zone (timezone)
│
▼
2. Submit target language and time zone update
│
▼
3. Re-read account preferences ──▶ Verify returned values match submitted values
Prerequisites¶
Complete the endpoint, personal access token, and workspace setup in Use the SDK.
Choose a supported locale identifier (such as
zh-CNoren-US) and time zone name (such asAsia/ShanghaiorUTC). Account preferences belong to the authenticated account directly and do not require binding a workspace.
Set the target locale and time zone in your terminal (any unset variable retains its current account value):
export TARGET_LOCALE='en-US'
export TARGET_TIMEZONE='UTC'
Read and update preferences¶
Read the current language and time zone first, submit the update request, and read back the preferences to verify that the saved values match.
import os
import moi_product_sdk as sdk
client = sdk.new_with_personal_access_token(
os.environ["PRODUCT_API_BASE_URL"],
os.environ["PRODUCT_API_KEY"],
)
before = client.account().preferences()
print("Current locale:", before.locale, "Current timezone:", before.timezone)
locale = os.environ.get("TARGET_LOCALE") or before.locale
timezone = os.environ.get("TARGET_TIMEZONE") or before.timezone
client.account().update_preferences(
sdk.AuthPreferencesRequest(locale=locale, timezone=timezone)
)
current = client.account().preferences()
print("Saved locale:", current.locale, "Saved timezone:", current.timezone)
if current.locale != locale or current.timezone != timezone:
raise RuntimeError("Read-back preferences do not match submitted values")
package main
import (
"context"
"fmt"
"os"
sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)
func main() {
ctx := context.Background()
client, err := sdk.NewWithPersonalAccessToken(
os.Getenv("PRODUCT_API_BASE_URL"),
os.Getenv("PRODUCT_API_KEY"),
)
if err != nil {
panic(err)
}
before, err := client.Account().Preferences(ctx)
if err != nil {
panic(err)
}
fmt.Println("Current locale:", before.GetLocale(), "Current timezone:", before.GetTimezone())
locale := os.Getenv("TARGET_LOCALE")
if locale == "" {
locale = before.GetLocale()
}
timezone := os.Getenv("TARGET_TIMEZONE")
if timezone == "" {
timezone = before.GetTimezone()
}
_, err = client.Account().UpdatePreferences(ctx, &sdk.AuthPreferencesRequest{
Locale: &locale,
Timezone: &timezone,
})
if err != nil {
panic(err)
}
current, err := client.Account().Preferences(ctx)
if err != nil {
panic(err)
}
fmt.Println("Saved locale:", current.GetLocale(), "Saved timezone:", current.GetTimezone())
if current.GetLocale() != locale || current.GetTimezone() != timezone {
panic("Read-back preferences do not match submitted values")
}
}
If an unsupported locale identifier or invalid time zone string is submitted, the server rejects the request with a validation error; correct the input values according to the error message and retry.