I have come across a method where we get the sha code when we hit the github url but once i have done the get request and have the tree code as well as the shacode. Once i perform the post operation i am getting 404 as the error can you help regarding this. i have achieved the same using rest api but want to do the same using sas studio program that i have created .
%let user="username";
%let pass="personaltoken generated at githu";
filename eqty "/home/mystudiodirectory/test.txt" lrecl=32000;
proc http
url="https://api.github.com/repos/user/repos/git/refs/heads/master"
method="GET" out=eqty webusername=&user
webpassword=&pass
ct="application/text";
run;
data firstrequest;
infile "/home/mystudiodirectory0/test.txt" dsd lrecl=3000000;
input x : $2000. @@;
retain flag;
pos=find(x, "sha");
if(pos>0) then
do;
flag=1;
var=scan(x, 3, '""');
shalatestcommit=scan(x, 5, '""');
end;
run;
data request2(keep=shalatestcommit);
set firstrequest;
if var not in ('sha') then
delete;
call symput('shaltcommit', trim(shalatestcommit));
run;
/*******************************second request**************************/
%let url=https://api.github.com/repos/user/repository/git/commits/&shaltcommit.;
filename eqty1 "/home/mystudiodirectory0/test1.txt" lrecl=32000;
proc http url="&url" method="GET" out=eqty1 webusername=&user
webpassword=&pass
ct="application/text";
data secondrequest;
infile "/home/mystudiodirectory0/test1.txt" dsd lrecl=3000000;
input x : $2000. @@;
retain flag1;
pos=find(x, "tree");
if(pos>0) then
do;
flag1=1;
var=scan(x, 1, '""');
treecommit=scan(x, 5, '""');
end;
run;
data request3(keep=treecommit);
set secondrequest;
if var not in ('tree') then
delete;
call symput('treecommit', trim(treecommit));
run;
/************************************************************/
*filename eqty3 "/home/mystudiodirectory0/test3.txt";
/*data store;
y=compress(symget(&body));
file eqty3;
put y;
run;*/
filename eqty2 "/home/mystudiodirectory0/test2.txt" lrecl=32000;
data _null_;
infile datalines;
file eqty2;
input;
put _infile_;
datalines;
{
"base_tree": "treecommit value",
"tree": [
{
"path": "NewFile1.txt",
"mode": "100644",
"type": "blob",
"content": "This is NewFile1."
}
]
}
;
run;
filename eqty3 "/home/mystudiodirectory0/test3.txt" lrecl=32000;
;
proc http url="https://api.github.com/repos/user/repository/git/trees"
method="POST" in=eqty2 out=eqty3 webusername=&user
webpassword=&pass;
data thirdrequest;
infile "/home/mystudiodirectory0/test3.txt" dsd lrecl=3000000;
input x : $2000. @@;
retain flag2;
pos=find(x, "sha");
if(pos>0) then
do;
flag2=1;
var=scan(x, 1, '""');
nwshalatestcommit=scan(x, 3, '""');
end;
run;
Before we look at anything else, I want to make you and other readers aware of this - in SAS 9.4 Maint 6, a new set of Git functions were introduced in the SAS programming language.
Read all about them in the doc. These might make your tasks easier to accomplish with less code.
The 404 error is "Not Found", and usually the simplest explanation is that the API call you've made isn't valid. Your program that you shared has placeholders for "repository" and "user" (assuming you would use your own username and a valid repository name), so check those first. I assume this is the API you're trying to use?
The 404 error still indicates that the API, as you're calling it in SAS, doesn't exist -- maybe something is just a little bit off. If it works in another REST client like Postman or cURL, then it should work in SAS as well.
I suggest adding the DEBUG statement to your PROC HTTP call and maybe you'll get more information about what you're sending/receiving.
Just to add an update: there are new Git functions in Base SAS, and experimental Git integration directly in SAS Studio. Read about these updates here: Using built-in Git operations in SAS.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.