BookmarkSubscribeRSS Feed

How to change user preferences with an API

Started ‎12-23-2024 by
Modified ‎12-23-2024 by
Views 1,723

APIs provide access to capabilities not standard in the user interface, not available to the admin through Manage Environment or through the Command Line Interface (CLI). A comprehensive list of documented APIs on https://developer.sas.com/ is available.  You can find many Categories like Auto Machine Learning, CAS, Compute and Jobs, Data Management, Fraud and Compliance, Health and Life Sciences, Models and Decisions, Platform Administration, Visual Investigator, Visualization and Reports and more. 

 

I solved the following use case with an API. "Customize the personal user setting for region and language."

This can be very useful if you want to unburden the users by doing this with a piece of code. "

 

Visual Analytics looks at the web browser the user is using for the language setting. The user has the option to override it with his personal settings. These settings affect, for example, the notation of thousands

 

           Numbers decimals.png

The notation of thousands may vary from country to country. In the Netherlands, for example, a period is used instead of a comma.

         Numbers decimals punt.png

 

The setting for Region and Language can be adjusted by going to the user icon, top right and choosing settings. then click on the option 'Region and Language' and on the right you can change the 'Browser locale' to the desired language.

       Settings.png

 

The following code allows you to see a user's current preferences.

------------------------------------------------------------

* Get the Viya Host URL;
%let viyaHost=%sysfunc(getoption(SERVICESBASEURL));

%let user = <user-id> ;

 

filename rprtOut temp ;

 

proc http
   method='Get'
   url="&viyaHost./preferences/preferences/&user.?start=0&limit=20"
   oauth_bearer = sas_services
   out=rprtOut;
   headers 'Accept' = 'application/json';
   headers 'Content-Type' = 'application/json';
run;

 

libname rprtOut json;

------------------------------------------------------------

 

If you navigate to the library rprtOut you can see the tables that have been created. The table 'Items' shows the current preferences of the user. With the limit statement you can see 20 lines at a time. By adjusting the starting value of 0 you can also see the other settings.

list of preferences.png

 

The id to override the browser locale is 'FormatLocale.DefaultLocale'. You can use the following code for that.

------------------------------------------------------------

* Get the Viya Host URL;
%let viyaHost=%sysfunc(getoption(SERVICESBASEURL));
 
%let new_value = nl_NL ;
%let user = <user-id> ;
 
filename rprtIn temp ;
 
data _null_;
     file rprtIn;
     put '{';
     put '  "id": "FormatLocale.DefaultLocale",';
     put '  "description": "a test object",';
     put '  "application": "SAS® Visual Analytics",';
         new_value = '"value": "' || "&new_value." || '",';
     put new_value ;
     put '  "version": 1';
     put '}';
run ;
 
filename rprtOut temp ;
 
proc http
    method='PUT'
    url="&viyaHost./preferences/preferences/&user./FormatLocale.DefaultLocale"
    oauth_bearer = sas_services
    in=rprtIn
    out=rprtOut;
    headers 'Accept' = 'application/json';
    headers 'Content-Type' = 'application/json';
run;
 
libname rprtOut json;

------------------------------------------------------------

 

This change is effective as soon as the user logs back into the environment.

 

Enjoy!

 

Version history
Last update:
‎12-23-2024 10:01 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags