BookmarkSubscribe

How Do You Work with APIs in SAS® Viya®? Q&A, Slides, Code, and On-Demand Recording

Watch this Ask the Expert session to explore multiple APIs (SAS Viya and CAS) to create an end-to-end example for modeling. 

 

Watch the webinar

 

Join Joe Furbee as he shows you the entire model development lifecycle, from folder creation to uploading and imputing data, to creating and deploying a model. During this webinar you will learn:

  • An introduction to SAS APIs.
  • How to perform actions using SAS REST APIs.
  • What programming languages to use to invoke APIs.

 

Sample code

The code used in the demonstrations during the webinar is available on GitHub.

 

Q&A 

The questions from the Q&A segment held at the end of the webinar are listed below. The slides from the webinar are attached.

 

Is the example (second demo in Postman), EtoE Modeling and Deployment, is that creating a project and pipeline?

Yes. Each step in that process is a part of that pipeline. When we did this in the GUI, this was the REST calls being made under the covers. The pipeline we built had an imputation node and the decision tree node where it’s going to train the model. Those were the individual calls we were making in Postman where we did the impute call and decision tree call. Those were making the same API calls and doing the same functions that we were doing when we were running that in the GUI. Those are being run in the GUI, it’s making those calls for you. When we saw it in Postman, we were making those calls manually.

 

Follow-up to question above, if the project already exists, then these steps are not necessary, correct?

Yes, that is correct. If the project already exists, you could skip forward in the API call to registering and publishing the model and then I want to score new data. Or if you’ve done all that and you want to retrain your model, there are APIs for that. You can see all those in the GUI.

 

What other platforms besides Postman do you recommend to run these API calls?

You can run them on anything that can make API calls. VS Code, Atom, Insomnia, soapUI, any developer IDE that can make API calls like that and organize them. You can also use a Jupyter notebook and make them through Python or R. You can do the same thing in other languages if you’re writing an application, say in JavaScript.

 

In PROC HTTP, is it best practice to use sas_services as the oauth_bearer?

If you are doing it from within SAS, yes, that’s the easiest way. If you are making those calls from an outside application, you would use PROC HTTP and have to supply an access token.

 

Is there a good walk through that shows how to authenticate with Postman?

The SAS Users blog post Authentication to SAS Viya: a couple of approaches provides a step-by-step for authentication to SAS Viya. The code in the post uses cURL, but could easily be translated into Postman calls. I will provide Postman collection examples for authentication on GitHub with the materials related to this webinar.

 

Similar to how you used Postman to create that model pipeline via API, can you use SAS code to generate the same in SAS Studio using PROC HTTP?

Certainly. The last example I showed in the webinar (REST API calls from SAS) briefly outlined how to use PROC HTTP (and PROC CAS) to make API calls from SAS Studio. You could use the same API calls I made in the Postman and Python examples. You’d just need to adjust handling the responses and variable assignments using SAS code.

 

To what level are these APIs secure and can we assign the capability that a specific user can call these APIs?

Yes. That’s all done through the SAS Authorization. You can set up specific groups and users. When you register a client, you decide what level of access (controlled by the scope parameter) you want that client to have. When you create your access token to make your API calls, the restrictions are already there.

 

Are any specific Python packages required to run the SAS/Python code that you demonstrated?

I used the Python requests, json, and getpass modules in the Notebook, but nothing special or proprietary. I’ll post a full version of the notebook on GitHub with the materials related to this webinar

 

Can we SAS 9.4 M6 to work with APIs in SAS Viya?

Yes, you can through PROC HTTP. At that point SAS9 would act as the SAS Client. You will need to supply an authorization code. You may have to take an additional step and get your access token. Then you can make API calls with PROC HTTP or PROC CAS through that SAS9 environment.

 

 

Recommended Resources

developer.sas.com

SAS Viya REST  APIs

CAS REST APIs

CAS Actions and Action Sets

SAS Global Forum 2021

 

Want more tips? Be sure to subscribe to the Ask the Expert board to receive follow up Q&A, slides and recordings from other SAS Ask the Expert webinars.  

Article Tags
Contributors