Many SAS Solutions use APIs to interface with 3rd party software or other SAS solutions. For instance, there’s a REST API for SAS® Anti-Money Laundering that retrieves a list of unique scoring dates for a specific customer. And, in SAS® Visual Investigator, you can use a REST API to create a data store connection, instead of creating the connection manually. The possibilities are endless with what you can do with APIs, however, APIs can be difficult to understand at first! In this post, I’ll start with the basics and give an introduction to APIs.
API stands for application programming interface.
APIs are a set of rules and protocols that enable different software components to communicate with each other. To us, APIs simply look like code or a particular programming language, but for computers, APIs provide a way to share data or functionality. An API works as a facilitator connecting software platforms that would otherwise not be able to interact, which enhances the user’s experience.
You probably use APIs daily without even knowing. For example, when you check the weather app on your phone, it’s most likely using an API to get the most current weather data from a service. Or, if you’re online shopping, and you use an online payment method. These payment systems are embedded into many websites that require financial transactions. The website interacts with the system, which connects to your personal financial information. The website itself does not have direct access to your financial information.
A common metaphor used to understand an API is ordering food at a restaurant. This metaphor involves you (the customer), the waiter, and the chef. You represent the client, the waiter in this metaphor represents the API, and the chef represents the server.
Let’s say that the waiter comes to your table, and you order a burger. The waiter gets your request for a burger and takes it to the chef, the person who’s making the burger. The waiter just helps you out with the different requests. When the burger is done, your waiter brings you food in the form of a burger, and you get to consume that burger in any way, shape, or form (that is, using your hands or using utensils).
Just like the waiter is the facilitator to connect you to the chef, APIs are the facilitators between software platforms to interact.
So far, I've covered a very brief overview of APIs. Let's now review an example of how to create a new Visual Investigator datastore by using a REST API request. I use Visual Studio Code in this example, but you can use any API application.
As with any REST API endpoint, I first need a valid access token to authenticate the request, which I’ve already obtained. There are many ways to obtain an access token. Please review the Initial Steps section of Maggie Redford's post for one example: Getting started with the REST APIs of Visual Investigator.
I’ll also need the credentials for the database I intend to connect to Visual Investigator with the newly created data store. I already have this information as well.
I’ll create a new request in Visual Studio Code by clicking File, New File. I enter create_datastore.http for the file name, and press enter. Note the http extension. Then, I click Create File.
Next, I define a few variables that will be used in the request.
The first variable is the baseUrl. In the file, I enter @baseURL = https://server.demo.sas.com. Next, I’ll define the access token, by entering @accessToken= and then copying the access token I obtained previously.
I enter POST and then add a reference to my base url and add the endpoint, which is svi-datahub/admin/dataStores.
On the next line, I add the Content-Type header and enter application/json. Next, I add the Authorization header and enter Bearer and reference my access token.
I add an extra line before I enter the request body. Do not forget this extra line!
I add the name of the database, which in this example is insurance. Then, I enter the database type, which is RELATIONAL, and the version which is 0.
Next, I add the connectionType, which is postgres and the host, which is server.demo.sas.com.
Then, I add the port number, which is 30432 and the username and password of the database we are connecting to, which is pgadmin and Student1.
Then, I add the databaseNameOrServiceName which is postgres, and the schema which is insurance.
Lastly, I include urlAppendedParameters which is ssl=prefer.
Select any image to see a larger version. Mobile users: To view the images, select the "Full" version at the bottom of the page.
Note the quotation marks in the request body.
After I save this request, I right-click and select Send Request. The database is then created!
This was a very brief overview of APIs. To learn more, please see the SAS developers documentation for REST APIs: Rest APIs | SAS
Below are the resources I used for this post:
Brewster, Cordenne. 2021. “7 Examples of APIs in Use Today.” trio (blog). https://www.trio.dev/back-end/resources/api-examples. Last modified August 13, 2021.
Khalid, Yasoob. 2023. “API For Dummies: Learning The Basics Of API.” ScrapingBee (blog). https://www.scrapingbee.com/blog/. Last modified January 29, 2023.
Taulien, Kalob. 2020. “The simplest way to think about an API (the metaphor).” O’Reilly Media, Inc. https://learning.oreilly.com/videos/understanding-apis-and/9781800564121/9781800564121-video2_1/
Find more articles from SAS Global Enablement and Learning here.
... View more