BookmarkSubscribeRSS Feed
mathias
Quartz | Level 8

Hello,

 

I would like to expose some data one the web through a json rest api.

I have no idea how it could be done. (I have experience building Stored processes with SAS EG (EG 7.1 & SAS 9.3) but that's about it)

 

Is it as simple as making a STP like this?

 

 

data _null_;
     file _webout;
     put '...';  
     run;

 

I tried that and when going to the url of the STP in a browser I see the json data.

 

But when retrieving the data with javascript from a web page on another server I get a cross-origin CORS error.

XMLHttpRequest cannot load https://xxx.xxx.xxx/SASStoredProcess/guest?_program=/yyy/yyy/yyy. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xxx.xxx.xxx' is therefore not allowed access.

 

 

$.ajax({
	dataType: "json",
	url: "//xxx.xxx.xxx/SASStoredProcess/guest?_program=/yyy/yyy/yyy",
	// data: data,
	success: function(data) {
		console.log(data);
	}
});

 

 

Is it possible to add the header "Access-Control-Allow-Origin:*" in the response?

Thanks!

3 REPLIES 3
mathias
Quartz | Level 8

 

Still have no idea if this is a good way for achieving this.

What happens when the STP gets more complicated and takes more than a fraction of a second to complete?

Is this REST?

VasilijNevlev
Quartz | Level 8

Hello Mathias, 

 

This is a perfectly valid way of coding a web service yourself. You also have valid concerns. 

 

Here are a few takeway notes: 

* Your web service works becasue you have manually logged on. Try to log out of SAS Stored Process Web Application and run the request, it will not work becasue SAS will ask you to authenticate when your ajax request won't handle that request. 

* Your way of changing headers applies only to your webservice. This means you can't use the same method to log in to your webservice as SAS Logon manager will not have the correct headers. 

* Default setting for SAS Web Server is to time out after one minute. It can be changed, but at the same time, would your users wait for at least 30 seconds to refresh a datasource on the screen? If web service takes more then a few seconds to fetch the data, something needs to change. 

 

I have two solutions to suggest: 

* Consider using an open source connector form Boemska: https://github.com/Boemska/h54s This is tried and tested way of getting data out SAS, but it requires certain level of access to the SAS platform. 

* Analytium, the company that I am working for, has a solution in the pipeline that makes it easier to integrate software with SAS. It would be great if I could give you a quick demo over WebEx to see how Analytium could help you get the most out SAS. If you are interested, just let me know your timezone, availability and email by sending me a private message: Send Message to Vasilij Nevlev 

 

Regards,

Vasilij

=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk
saspert
Pyrite | Level 9

See if this helps. We ran into a CORS on a AWS server hosting the sas stored process web app. 

 

http://support.sas.com/kb/59/957.html

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2295 views
  • 1 like
  • 3 in conversation