Save action does not work by REST api

Posts: 29

Save action does not work by REST api




I am a new user who is trying to getting familiar with sas viya and CAS Rest API. I found I came across an issue while I tried to submit save andd drop actions by REST api. 


Below is my load table and fetch actions,


var Indata={table: {name:'cart',caslib:'MYCASLIB3'}};
var loadT={caslib:'MYCASLIB3',path:'cart.sashdat',casout:{name:'cart',caslib:'MYCASLIB3'}};
            method: "POST",
            url: baseURL+'/actions/fetch',


The fetch response I got from the server is like this:



And then I used runCode Action and the parameters I send is:
                            var Code={code:thecode,single:'yes'};
(log of thecode
data cart(caslib='MYCASLIB3');length id 8 name $100 units 8 price 8 ;id=1000;name="iphone5s";units=1;price=4300;output;runSmiley Wink 
var savep={caslib:'MYCASLIB3',name:'cart.sashdat',table:{name:'cart',caslib:'MYCASLIB3'},replace:true};
                                                   }).then(function callBack(response)
                                                                     }).then(function callback(response)  
                                                                             function errorcallback()
        },function error(){}
The response I got from the server is below:
The result  of runcode action:
The result ​of save Action:
After I save it, I dropped the cas table. 
And then I reload the page, I think I was supposed to see a new table with one row but I still got the previous table. 
The reason I think I had something wrong with my save action and drop action is, when I click the buttton to submit save and drop action, I used fetch action in sas studio to have a look at the cart table, and I got:
proc cas;
table.fetch /
table= {name='cart};
Selected Rows from Table CART _Index_ id name units price



So it means that the cas table is changed, which means my runcode action works. However, notice that I can fetch the table successfully without reloading the table, which means my droptable action does not work. 
But when I reloaded the web page and looked at my loadtable action, I found it said table was sucessfully loaded instead of table already exists, while it get the previous data. So it means it did drop table in somewhere, or may save the table too in somewhere, but I don't know where those things happen. 
Anybody has a clue about that?  Thank you in advance!


SAS Employee
Posts: 417

Re: Save action does not work by REST api

Posted in reply to xiaoys0725



It's really hard to say what happened without checking the log file. So, if you do not mind, add the following to your CAS server's log configuration file (/opt/sas/viya/config/etc/cas/default/logconfig.xml) to trace REST API invocations and results to the CAS server log:



<logger name="">
<level value="trace"/>



Restart CAS server, repeat a problem and send to me the most recent CAS server log from:


Posts: 29

Re: Save action does not work by REST api

Hello, I firgured out the reason. The reason is when I sent the request(load table) by Ajax in angularjs, although I set parameter as "table:{name:'cart',caslib:'MYCASLIB3'}", the name of the table becomes "{name:'cart'}"( something like this, I forget the detail, it might be "{name:'cart'} " possibly.) So when I used runCode action to write new records, it actually wrote records into table 'cart' instead of  "{name:'cart'}". Then you can see yes I did save the table, but it was I load and saved exactly the same table, instead of the new table. 


I solved the problem partialy by setting parameter as "table:'cart'", but I don't like this way quite much since I still wanna assign this table to a global caslib instead of a session caslib generated automatically. Do you have any ideas how to fix it? 



Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation