SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

I am trying to convert this 

curl --request GET \
--header 'Content-Type: application/json' \
--header 'X-API-TOKEN: '
 
into a SAS Code (see the code below) in order to obtain the fileid.  However, I am getting an 404 error which means I think that the URL is not good.  HouF!
 
/* GET REPONSE EXPORT PROGRESS */
options set=SSLREQCERT="allow";
filename progr temp;
proc http
url="https://ca1.qualtrics.com/API/v3/responseexports/"
method= "GET"
in="{""exportProgressId"" : ""&ProgressID"",""surveyId"" : ""&SurveyID""}"
out=progr;
 headers   
   'x-api-token'= &Api_Token.
   'Content-Type'='application/json';
run;
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The cURL and PROC HTTP URL should be the same here.

URL="https://yul1.qualtrics.com/API/v3/surveys/surveyId/export-responses/exportProgressId"

Only URL parameters (set off by ? and &) would transcribe to the IN= option the way that you tried.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

5 REPLIES 5
ChrisHemedinger
Community Manager

The cURL and PROC HTTP URL should be the same here.

URL="https://yul1.qualtrics.com/API/v3/surveys/surveyId/export-responses/exportProgressId"

Only URL parameters (set off by ? and &) would transcribe to the IN= option the way that you tried.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
alepage
Barite | Level 11

Hello Chris,

 

I have started this project as follow:

 

/* First Step, looking at the survey list available */
%let Api_Token='**********************************wJOJfD74l0sc1';
options set=SSLREQCERT="allow";
filename resp temp;

PROC HTTP
METHOD="GET"
URL= 'https://ca1.qualtrics.com/API/v3/surveys'
OUT=resp;
headers
'x-api-token'= &Api_Token.;
run;

/* Let the JSON engine do its thing */
libname posts JSON fileref=resp;
title "Automap of JSON data";

/* examine resulting tables/structure */
proc datasets lib=posts; quit;
proc print data=posts.alldata; run;

data Basic_survey_info (drop=ordinal_result ordinal_elements);
set posts.result_elements;
obs=ordinal_elements;
run;
/* Choosing the good survey by providing a partial name and putting the SurveyID into a macro variable*/
%macro GetSurveyID(Partial_Survey_Name);
data Basic_survey_info;
set Basic_survey_info;
if find(name,"&Partial_Survey_Name.",'i') ge 1 then call symputx('SurveyID',id,'g');
run;
%mend GetSurveyID;
%GetSurveyID(Morgex);
%put &=SurveyID;and it works

This script below is working:

 

options set=SSLREQCERT="allow";
filename rsp temp;
proc http
url="https://ca1.qualtrics.com/API/v3/responseexports/"
method= "POST"
in="{""format"" : ""csv"",""surveyId"" : ""&SurveyID""}"
out=rsp;
 headers   
   'x-api-token'= &Api_Token.
   'Content-Type'='application/json';
run;
/* Let the JSON engine do its thing */
libname RSP JSON fileref=rsp;
title "Automap of JSON data";

/* examine resulting tables/structure */
proc datasets lib=RSP; quit;

proc print data=RSP.alldata; run;
proc print data=RSP.meta; run;
proc print data=RSP.result; run;

Data ReponseExport;
set rsp.alldata;
if p2 = 'id' then call symputx('ProgressID',value,'g');
if p2 = 'requestId' then call symputx('RequestID',Value,'g');
run;

Is there a way to find what's could be the good url for the reponse export progress

 

ChrisHemedinger
Community Manager

I'm not an expert on Qualtrics API, but you can look at the entire JSON response with the JSONPP function:

 

data _null_;
 rc=jsonpp('rsp','log');
run;

That might reveal a field that shows the status or progress URI, which you could then use in another call.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
alepage
Barite | Level 11

How this function works if I want to get the json reponse of qualtric.com

 

Could you please provide an example of SAS code?

alepage
Barite | Level 11

I have carry out other tests and here's my last script.

 

/* First Step, looking at the survey list available */
%let Api_Token='****************************fD74l0sc1';
options set=SSLREQCERT="allow";
filename resp temp;
 
PROC HTTP
    METHOD="GET"
    URL= 'https://ca1.qualtrics.com/API/v3/surveys'
    OUT=resp;
    headers
    'x-api-token'= &Api_Token.;
run;
 
/* Let the JSON engine do its thing */
libname posts JSON fileref=resp;
title "Automap of JSON data";
 
/* examine resulting tables/structure */
proc datasets lib=posts; quit;
proc print data=posts.alldata; run;

data Basic_survey_info (drop=ordinal_result ordinal_elements);
set posts.result_elements;
obs=ordinal_elements;
run;
/* Choosing the good survey by providing a partial name and putting the SurveyID into a macro variable*/
%macro GetSurveyID(Partial_Survey_Name);
data Basic_survey_info;
set Basic_survey_info;
if find(name,"&Partial_Survey_Name.",'i') ge 1 then call symputx('SurveyID',id,'g');
run; 
%mend GetSurveyID;
%GetSurveyID(Morgex);
%put &=SurveyID;

/* We have put SurveyID in the macro variable, &SurveyID.*/

/* Create Response Export / Start Response Export */
/* In that step, we need to provide the SurveyID (see previous step)
   in order to get the RequestID as well as the ProgressID */

/******************************************************************************************/
options set=SSLREQCERT="allow";
filename rsp temp;
proc http
url="https://ca1.qualtrics.com/API/v3/surveys/&SurveyID./export-responses/"
method= "POST"
in='{"format" : "csv"}'
out=rsp;
 headers   
   'x-api-token'= &Api_Token.
   'Content-Type'='application/json';
run;
/* Let the JSON engine do its thing */
libname RSP JSON fileref=rsp;
title "Automap of JSON data";

/* examine resulting tables/structure */
proc datasets lib=RSP; quit;

proc print data=RSP.alldata; run;
proc print data=RSP.meta; run;
proc print data=RSP.result; run;

Data ReponseExport;
set rsp.alldata;
if p2 = 'progressId' then call symputx('ProgressID',strip(value),'g');
if p2 = 'requestId' then call symputx('RequestID',strip(Value),'g');
run;
%put &=ProgressID &=RequestID;

/* GET REPONSE EXPORT PROGRESS */
options set=SSLREQCERT="allow";
filename progr temp;
proc http
url="https://ca1.qualtrics.com/API/v3/surveys/&surveyId./export-responses/&ProgressID."
method= "GET"
out=progr;
 headers   
   'x-api-token'= &Api_Token.
   'Content-Type'='application/json';
run;

/* Let the JSON engine do its thing */
libname progr JSON fileref=progr;
title "Automap of JSON data";

/* examine resulting tables/structure */
proc datasets lib=progr; quit;

proc print data=progr.alldata; run;
proc print data=progr.meta; run;
proc print data=progr.result; run;

Data ReponseExport;
set progr.alldata;
if p2 = 'fileId' then call symputx('FileID',strip(value),'g');
run;
%put &=FileID.;

/*Get Response Export File*/

options set=SSLREQCERT="allow";
filename expfile '/.../test3.txt';
proc http
url="https://ca1.qualtrics.com/API/v3/surveys/&surveyId./export-responses/&FileID./file"
method= "GET"
out=expfile;
 headers   
   'x-api-token'= &Api_Token.
   'Content-Type'='application/json';
run;

This script works but when I look into test3.txt here's what I see below .  Any idea how to solve that issue.

 

PK

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4100 views
  • 0 likes
  • 2 in conversation