AnsweredAssumed Answered

API Access to user preferences?

Question asked by community-support on Jan 13, 2014
Latest reply on Jan 13, 2014 by community-support
I'm building a calendar for the front end of our web application that needs to be able to grab the selected users time zone. In SugarCRM, the user can set this data in their profiles. But when pulling a user account through the API, there doesn't seem to be any way to access their user preferences. Looking in the DB, the user preferences aren't stored within a single column for each preference, but rather a serialized array that is then base64 encoded. Since I don't know of a direct way to get this data through the API, the standard way would be to do a direct SQL query, which I'm very much against. Everything else I've built is done strictly on API calls, even ACLs. Here's a POC on the basics.

[code]

QUERY -> SELECT FROM_BASE64( 'contents' ) FROM 'user_preferences' WHERE 'category' = 'global' AND 'assigned_user_id' = 'SUGAR_USER_ID_HASH' LIMIT 1;

RESULT -> a:39:{s:20:'calendar_publish_key';s:36:'de6740b6-8983-2b39-1f1e-51713487c852';s:10:'user_theme';s:6:'Sugar5';s:13:'reminder_time';s:4:'1800';s:12:'mailmerge_on';s:2:'on';s:8:'timezone';s:15:'America/Toronto';s:16:'swap_last_viewed';s:0:'';s:14:'swap_shortcuts';s:0:'';s:19:'navigation_paradigm';s:2:'gm';s:13:'subpanel_tabs';s:0:'';s:14:'module_favicon';s:0:'';s:9:'hide_tabs';a:0:{}s:11:'remove_tabs';a:0:{}s:7:'no_opps';s:3:'off';s:19:'email_reminder_time';i:-1;s:2:'ut';s:1:'1';s:8:'currency';s:3:'-99';s:35:'default_currency_significant_digits';s:1:'2';s:11:'num_grp_sep';s:1:',';s:7:'dec_sep';s:1:'.';s:5:'datef';s:5:'m/d/Y';s:5:'timef';s:4:'h:ia';s:26:'default_locale_name_format';s:5:'s f l';s:14:'use_real_names';s:2:'on';s:17:'mail_smtpauth_req';s:0:'';s:12:'mail_smtpssl';i:0;s:17:'email_show_counts';i:0;s:19:'theme_current_group';s:3:'All';s:10:'EmployeesQ';a:3:{s:6:'module';s:9:'Employees';s:6:'action';s:5:'index';s:5:'query';s:4:'true';}s:25:'Releases_RELEASE_ORDER_BY';s:10:'list_order';s:9:'ContactsQ';a:11:{s:6:'module';s:8:'Contacts';s:6:'action';s:5:'index';s:9:'parentTab';s:5:'Sales';s:9:'ajax_load';s:1:'1';s:14:'loadLanguageJS';s:1:'1';s:13:'searchFormTab';s:12:'basic_search';s:5:'query';s:4:'true';s:17:'search_name_basic';s:0:'';s:23:'current_user_only_basic';s:1:'0';s:6:'button';s:6:'Search';s:14:'forQuickCreate';b:1;}s:10:'shared_ids';a:1:{i:0;s:36:'85be3f7b-e199-6c84-1b99-51ae24027b1e';}s:9:'MeetingsQ';a:12:{s:6:'module';s:8:'Meetings';s:6:'action';s:5:'index';s:13:'return_module';s:8:'Meetings';s:13:'return_action';s:10:'DetailView';s:9:'parentTab';s:10:'Activities';s:9:'ajax_load';s:1:'1';s:14:'loadLanguageJS';s:1:'1';s:13:'searchFormTab';s:12:'basic_search';s:5:'query';s:4:'true';s:10:'name_basic';s:0:'';s:23:'current_user_only_basic';s:1:'0';s:15:'open_only_basic';s:1:'0';}s:4:'fdow';s:1:'0';s:15:'mail_smtpserver';s:0:'';s:13:'mail_smtpuser';s:0:'';s:13:'mail_smtppass';s:0:'';s:16:'export_delimiter';s:1:',';s:22:'default_export_charset';s:5:'UTF-8';s:15:'email_link_type';s:5:'sugar';}

$result = unserialize( $query );

$timezone = $result['timezone']; // America/Toronto

[/code]

Surely there must be a better way to do this without having to do direct DB queries? Or if it's not directly accessible through the API, is there a way to get this Base64 string without having to do direct DB queries?

(from allan@activationproducts.com)

Outcomes