/****************************************************************************** * Programme : SAS Viya : Automatisez l'extraction des groupes d'utilisateurs via l'API REST * Reference : MACROPADCA * Source : https://www.wearecas.eu/en/sampleCode/MACROPADCA ******************************************************************************/ /* --- BLOC 1 --- */ %macro mv_getgroups( access_token_var=ACCESS_TOKEN, grant_type=sas_services, outds=work.viyagroups ); %local oauth_bearer base_uri fname1 libref1; %if &grant_type=detect %then %do; %if %symexist(&access_token_var) %then %let grant_type=authorization_code; %else %let grant_type=sas_services; %end; %if &grant_type=sas_services %then %do; %let oauth_bearer=oauth_bearer=sas_services; %let &access_token_var=; %end; %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password and &grant_type ne sas_services ) ,mac=&sysmacroname ,msg=%str(Invalid value for grant_type: &grant_type) ) options noquotelenmax; /* location of rest apis */ %let base_uri=%mf_getplatform(VIYARESTAPI); /* --- BLOC 2 --- */ %let fname1=%mf_getuniquefileref(); %let libref1=%mf_getuniquelibref(); proc http method='GET' out=&fname1 &oauth_bearer url="&base_uri/identities/groups?limit=10000"; headers %if &grant_type=authorization_code %then %do; "Authorization"="Bearer &&&access_token_var" %end; "Accept"="application/json"; run; /*data _null_;infile &fname1;input;putlog _infile_;run;*/ %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200) ,mac=&sysmacroname ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE) ) libname &libref1 JSON fileref=&fname1; /* --- BLOC 3 --- */ data &outds; set &libref1..items; run; /* clear refs */ filename &fname1 clear; libname &libref1 clear; /* --- BLOC 4 --- */ %mend mv_getgroups;