Hello,
Here's the shell / cURL code:
curl --request POST \ --url https://yul1.qualtrics.com/API/v3/directories/directoryId/mailinglists/mailingListId/transactioncontacts \ --header 'Content-Type: application/json' \ --header 'X-API-TOKEN: token-value' \ --data '{ "transactionMeta": { "batchId": "BT_ZZZZ45678901234", "fields": [ "string" ] }, "contacts": [ { "firstName": "string", "lastName": "string", "email": "string", "extRef": "string", "embeddedData": { "property1": "string", "property2": "string" }, "language": "string", "unsubscribed": true, "transactionData": {} } ] }'
How do we convert this script into sas code ? Could you please provide an example where we add two new contacts and another example where we will provide a json file.
cURL is usually easy to transcribe into PROC HTTP. Looking at the elements in your cURL script:
filename resp temp;
proc http
method='POST'
url="https://yul1.qualtrics.com/API/v3/directories/directoryId/mailinglists/mailingListId/transactioncontacts"
CT="application/json"
in='{ "transactionMeta": { "batchId": "BT_ZZZZ45678901234", "fields": [ "string" ] }, "contacts": [ { "firstName": "string", "lastName": "string", "email": "string", "extRef": "string", "embeddedData": { "property1": "string", "property2": "string" }, "language": "string", "unsubscribed": true, "transactionData": {} } ] }'
out=resp;
headers "X-API-TOKEN"="your-token-value";
run;
/* Check HTTP response code */
%put &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE;
/* print response to log */
data _null_;
rc=jsonpp('resp','log');
run;
The IN= can also take a filename/fileref, so if your data is in an external JSON file, use that method.
The response from the API, assuming it is JSON, can be read as SAS data using the JSON engine:
libname data json fileref=resp;
Hello,
I have saw your example at the url:
where you are using the following code which I think is easier to read.
Does the datalines portion will look like that and with or without the apostrophe? Do we put a carriage return line feed to separate each new contact info ?
datalines;
{ "transactionMeta": { "batchId": "BT_ZZZZ45678901234", "fields": [ "string" ] }, "contacts": [ { "firstName": "string", "lastName": "string", "email": "string", "extRef": "string", "embeddedData": { "property1": "string", "property2": "string" }, "language": "string", "unsubscribed": true, "transactionData": {} } ] }
run;
/* Put the body of the JSON content in external file */
filename json_in temp;
data _null_;
file json_in;
input;
put _infile_;
datalines;
{ "name":"value" }
run;
If you use that approach (which I agree is more readable), you can put the JSON content on multiple lines, as long as the complete data remains valid JSON. Break the lines at sections like commas or braces, not in the middle of quoted values.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.