Hi All,
I'm trying to do a API requisition through EG but I have no success in my call. I've tested it in Postman and there it is working normally.
I need passing 6 fields variables on Body, then I think that's need using the PUT, right?
Below there is my example, using only one field on body:
%let val = "SMS2"; /* Put the body of the JSON content in external file */ filename json_in temp; data _null_; file json_in; put; put "{"; put '"Tp_SMS":'"&val."; put "}"; run; proc http url="https://xxxxxxxxxxxxxx/xxxxx/xxxx/xxxxx" method="POST" ct="application/x-www-form-urlencoded" in=json_in out=posta headerout=hdrout; headers "Host"="xxxxxxx" "Authorization"="bearer XXXXXXXXXXXXXX" "Content-Type"="application/json" "Content-Length"="xxxxxxx" "CD_Login"="xxxxxxx"; Run;
How can I solved it? How I should add others fields varsiables on body - using PUT?
Important: If I use the "Datalines" than "PUT", with one field - I have success.
Any help will be very appreciated.
Tks,
TF
Please show the non-macro version using datalines that does work.
I am not quite sure exactly what you need. But if you want a JSON file with the 6 fields, it might be easier (if you have SAS 9.4) to use the JSON procedure. Here is code I put together that I think creates the file you want:
proc json out="./tfabri.json" pretty nosastags;
write open object;
write values "SMS2" "&val";
write values "field_2" "field_2_value";
/* Add the other 4 values */
write close;
run;
Here are the contents of the file:
{ "SMS2": "SMS2", "field_2": "field_2_value" }
Hi Bill, thank you for your answer.
I'm still working on this. With your suggestion I can create a JSON file, but when I tried to run HTTP PROC (using this JSON file) I was not successful.
FILENAME JSON_IN TEMP;
PROC JSON OUT="C:\TEMP\TESTE_NOVO.JSON" PRETTY NOKEYS NOSASTAGS;
WRITE OPEN OBJECT;
WRITE VALUES "TP_SMS" "CCSMS";
WRITE VALUES "NM_REMETENTESMS" "TESTE";
WRITE VALUES "NR_TELEFONECELULARSMS" "1";
WRITE VALUES "TX_MENSAGEMSMS" "MSG";
WRITE VALUES "DT_PARAENVIOSMS" "1";
WRITE VALUES "DT_LIMITEENVIOSMS" "S";
WRITE VALUES "DS_CHAVEORIGEMSMS" "1";
WRITE CLOSE;
RUN;
FILENAME POSTA "C:\TEMP\POSTA.TXT";
PROC HTTP
URL="HTTPS://***********/*******/CORPO/SMS/INCLUISMS"
METHOD="POST"
CT="APPLICATION/X-WWW-FORM-URLENCODED" /*JSON" */
IN=JSON_IN
OUT=POSTA;
HEADERS
"HOST"="*******"
"AUTHORIZATION"="BEARER &TOKEN"
"CONTENT-TYPE"="APPLICATION/JSON"
"CONTENT-LENGTH"="**"
"CD_LOGIN"="******";
RUN;
%PUT HTTP STATUS CODE = &SYS_PROCHTTP_STATUS_CODE. : &SYS_PROCHTTP_STATUS_PHRASE.;
Any additional suggestion?
Thanks a lot.
Tf
I am not a PROC HTTP expert but, I do not see how the JSON file you created in being used by the HTTP code based on what you posted. You are writing the JSON to the teste_novo.json file. The input for PROC HTTP is specified as JSON_IN. The filename statement specifies JSON_IN as the TEMP device type. The TEMP device just creates a temporary file for the lifetime of the FILENAME statement. In the SAS code that you posted, I do not see how the JSON file gets placed into the JSON_IN temporary location. To use the JSON file you created, I think that the PROC HTTP statement needs to have the IN argument modified to:
IN="C:\temp\teste_novo.json"
Hi Bill, thank you for your contact.
I've tried it on past without success. EG returned the error below:
I'm still trying found a way to solve it. Any new idea / tips / suggestion, will be very appreciated.
Thank you again,
TF
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.