38%macro ms_getgroups(user=0,uid=0,outds=work.ms_getgroups,mdebug=0);
39%local fref0 fref1 libref optval url table dsid rc schema;
41%mp_abort(iftrue=(&syscc ne 0),mac=ms_getgroups.sas
42 ,msg=%str(syscc=&syscc on macro entry))
44%let schema=work.%mf_getuniquename(prefix=ms_getgroups);
45%mddl_getgroups(&schema)
48 if 0 then
set &schema;
49 call missing(groupuri,groupname,groupdesc);
53%
if %sysget(MODE)=desktop %then %
do;
55 if 0 then
set &schema;
57 groupname=symget(
'sysuserid');
58 groupdesc=cats(symget(
'sysuserid'),
' (group - desktop mode)');
65%let fref0=%mf_getuniquefileref();
66%let fref1=%mf_getuniquefileref();
67%let libref=%mf_getuniquelibref();
68%let optval=%sysfunc(getoption(bomfile));
72 file &fref0 lrecl=1000;
73 infile
"&_sasjs_tokenfile" lrecl=1000;
75 if _n_=1 then put
'accept: application/json';
79%
if %superq(user) ne 0 %then %let url=/SASjsApi/user/by/username/&user;
80%
else %
if %superq(uid) ne 0 %then %let url=/SASjsApi/user/&uid;
81%
else %let url=/SASjsApi/group;
83proc http method=
'GET' headerin=&fref0 out=&fref1
84 url=
"&_sasjs_apiserverurl.&url";
85%
if &mdebug=1 %then %
do;
91%
if &syscc ne 0 or %superq(SYS_PROCHTTP_STATUS_CODE) ne 200 %then %
do;
94 %
if (%superq(user) ne 0 or %superq(uid) ne 0)
95 and %superq(SYS_PROCHTTP_STATUS_CODE)=404 %then %
do;
96 %put NOTE: MS_GETGROUPS user or uid not found, no groups returned.;
99 %put %str(ERR)OR: MS_GETGROUPS HTTP status &SYS_PROCHTTP_STATUS_CODE.;
102 filename &fref0 clear;
103 filename &fref1 clear;
107libname &libref JSON fileref=&fref1;
108%
if %superq(user)=0 and %superq(uid)=0 %then %let table=root;
109%
else %let table=groups;
112%let dsid=%sysfunc(open(&libref..&table,i));
114 %let rc=%sysfunc(varnum(&dsid,uid));
115 %let dsid=%sysfunc(close(&dsid));
118 if 0 then
set &schema;
119 set &libref..&table(keep=uid name description);
122 groupdesc=description;
123 keep groupuri groupname groupdesc;
128 %put %str(ERR)OR: MS_GETGROUPS unable to open JSON table &table.;
131libname &libref clear;
132filename &fref0 clear;
133filename &fref1 clear;