Customers are requesting to update user preferences such as themes, units for distance, etc, based on group membership. SAS Viya enables users to update their own preferences through the user interface. However if an administrator needs to change those, it can be harder as they are set at user level and not at group level. Using code we can now update large amounts of users or user groups pretty easily.
SAS Viya is built on REST architecture. It makes it really easy for administrator to call the REST APIs to achieve actions that are not implemented in the user interface or to automate actions. Here are the high level steps that are required to update the preferences: configure the SAS environment for API use, download the Python code I've provided, determine the users for which the preferences should be updated, then finally, execute the Python code from command-line.
In order to execute the code, you should have access with administrative rights to an environment where SAS Viya and Python are installed (it does not necessarily have to be on the same machine).
Configuring the SAS environment for API use is described on developer.sas.com. Here are the steps to be performed by a SAS administrator:
To validate the configuration, execute the following line from the command-line. Be sure to use your environment specifics for the the values in bold below:
curl -X POST "https://server.example.com:80/SASLogon/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=password&username=USERID&password=PASSWORD" \
-u "app:mysecret"
The curl command should be written on one line.
If the authentication is successful, a JSON string is returned with an access_token (see short version below).
{"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6ImxlZ2Fj
...
1GNzuN2nRmKDOU","expires_in":43198,"scope":"openid",
"jti":"9979232b6d10456ea575e2a1bafb6d24"}
If it fails, an error like the one below will appear:
{"error":"unauthorized","error_description":"Bad credentials"}
If you get an error, please make sure that the command contains the correct information. If the parameters are correct, it might indicate that the step 1 and 2 were not performed properly. You should validate with the administrator that the steps were properly achieved and that the parameters in the curl command are correct.
In order to execute the provided code, we will need an environment where Python is installed with the required package.
pip install --user requests
Now that we have both the SAS environment ready for API use and the Python environment ready, we need to identify which user or group of users we want to update the preferences for.
We will need the ID of the user or group.
In order to execute the code, we need to know which preference should be updated and which value can be set. The provided Python code contains these name/value pairs in the area names POSSIBLE VALUES:
Now that we have identified the users/groups and the preference/value, we can execute the code which will update the SAS Environment. As mentioned earlier, we will use the command-line to execute it.
Preference for "VA.geo.drivedistance.unit" has been set to "miles" for user sbxxab
Interesting post Xavier. Are the identities and preferences services you are using in your Python script documented anywhere?
Thank you for the feedback.
developer.sas.com doesn't cover the identities and preferences end-points. You can call those rest API's to get a better idea on how they can be used. A GET request will return the possible verbs and their parameters in a JSON object. If you need more information, please let me know and I will do my best to answer your questions.
Great info and great script @XavierBizoux . I wanted to provide a link to a series of SAS users blogs I wrote on REST APIs and SAS Viya for further info.
@rrc102 , this link for SAS Viya Idenity Management may have some of the info you are looking for.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.