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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4519 views
  • 0 likes
  • 2 in conversation