Watching Joe Furbee's webinar, Using SAS APIs, inspired me to learn more about the power of Postman for working with SAS REST APIs. In this article, I will review what I learned by showing an example Postman collection I created to Search for Tags (Annotations).
In SAS Viya, you can use tags to add extra information beyond simple metadata to tables, columns, and other objects. In the user interface, these tags can be added to columns automatically when profiling the data or manually added. Currently, you can't search for which items have a specific tag in the user interface; however, you can use the Annotations REST API service to do this. This is the example I will use to review what I learned about how the features of Postman can be leveraged to work with SAS REST APIs.
Postman is a useful tool for working with REST APIs. Collections allow you to group and save individual requests. You can also create folders within a collection for additional organization. The example collection I will review in this article is pictured below:
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
When working with requests in Postman collections you may use the following components:
Use Environment Variables to make your Postman requests more generic and re-usable. You can change the values of these variables based on your environment. This is optional for SAS REST API requests.
These variables are referenced in Postman in two different ways depending on where they are used. If used in the Request URL, Params, Authorization, Header, or Body section, then use the syntax {{Environment_Variable_Name}}. If used in the Pre-request Script or Tests section, then use the syntax pm.environment.get("Environment_Variable_Name").
Select the HTTP method of the request. Common ones used by SAS REST APIs are GET, POST, and DELETE. This is required for SAS REST API requests.
Enter the URL for your request based on the SAS REST API documentation. This is required for SAS REST API requests.
Use to send path and query parameters. These are the items after ? in the Request URL. Typically, this is optional for SAS REST API requests.
Select the type authorization and supply the appropriate information. Typically, this is required for SAS REST API requests and for most SAS REST API requests you will use the type of Bearer Token and supply the Access Token.
Provide the additional metadata needed to perform the operation of the request. Typically, this is required for SAS REST API requests.
Enter the data you need to send with the request. Typically, this is required for SAS REST API requests.
Write JavaScript code to execute before the request runs. This can be used to perform any necessary pre-processing such as setting of variable values. This is optional for SAS REST API requests.
Write JavaScript code to execute after the request runs. This can be used to perform any necessary post-processing such as performing a visualization of the response data. This is optional for SAS REST API requests.
When you click the Send button for your request, the Response from the request is displayed in the bottom half of the screen.
Returns the status code of the response from the request. Typically, a status code of 200 corresponds to an OK (successful) response. For the response codes for specific SAS REST API requests view its documentation.
This mode formats the response for easier viewing.
This mode contains the raw response text with no formatting.
This mode renders the response in a sandboxed iframe.
View any visualizations coded for the response from the request. Note: Postman 7.11 or later is required to perform these visualizations of the response. For more information on visualizing API responses, refer to the Postman documentation.
If you have used Postman before you will be familiar with most of these components, but the ones that I had never used before and found instrumental in building my reusable Postman collection of requests were:
The Search Tags Postman Collection consists of three requests:
and its associated Environment Variables.
This collection uses the GEL_Shared-SearchTags Environment Variables. Confirm and change the environment variable settings as needed for your environment.
Note: The default values are setup to work on the GEL Viya 3.5 Shared Image RACE Collection.
Change this variable to search for a different tag name.
This Postman collection contains a series of requests to perform a search on items with a specific tag name.
This request is a series of REST API calls to register the Client_ID and obtain an Access Token for Viya and CAS REST API calls. This procedure is needed to perform any Viya or CAS REST API calls. For more information review the SAS REST APIs: Authentication & Authorization documentation.
Below is the Pretty response from running the Register_Client_ID_and_Get_Access_Token request.
Below is the Visualize response from running the Register_Client_ID_and_Get_Access_Token request.
This request is a series of REST API calls to search for items with a particular tag name. In the example, the tag_name environment variable is set to Individual.
Below is the Pretty response from running the Search_Tags request.
Below is the Visualize response from running the Search_Tags request.
This request is a series of REST API calls to delete the Client_ID that was established for Viya and CAS REST API calls. This is to clean-up the authentication and authorization process and allow the Client_ID to be re-used again in the future.
Below is the Pretty response from running the Delete_Client_ID request. Note: 404 Not Found is the response you will receive if the Client_ID is deleted or not found.
Below is the Visualize response from running the Delete_Client_ID request.
In conclusion, creating Postman collections and using environment variables, pre-requests, and tests is an effective way to group requests together and make them more reusable between different environments.
For more information on Postman, please refer to its documentation. For more information on SAS Viya REST APIs, please refer to its documentation.
Thanks to Joe Furbee (@joeFurbee) for his inspiring webinar that encouraged me to learn more about the functionality of Postman and using it to work with SAS REST APIs.
Thank you for this posting. I am about to do some testing on VI. this will be very helpful
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.